Remove __del__ functions and terminate connection explicitly.

Originally, we rely on __del__ to clean connection, close files, but
the __del__ function is not so reliable. It won't be called in some
corner cases. For example, the cyclic link trick that prevents to
trigger garbage collection.

Another case is that if we call logging function in __del__ of other
instance, and logging module is already close the logging file, then
it will reopen the logging file and truncate all content of the file.

Therefore, we replaced all __del__ method with "Close" and called it
explicitly before the program ends.

BUG=none
TEST=make test

Change-Id: I0e741585085de150306e04f2140ba1b8a0dd6bca
Reviewed-on: https://chromium-review.googlesource.com/455717
Commit-Ready: Chih-Yu Huang <akahuang@chromium.org>
Tested-by: Chih-Yu Huang <akahuang@chromium.org>
Reviewed-by: Joel Kitching <kitching@chromium.org>
6 files changed