tqt TorDetector: close socket - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 52f4189176842395c0510ee812fc62b5af2f1ce0 DIR parent e60aede77ed4cccede0c8416c039ea7ad204c40d HTML Author: SomberNight <somber.night@protonmail.com> Date: Tue, 6 Oct 2020 19:15:20 +0200 qt TorDetector: close socket ResourceWarning below is shown when running python3 with "-X dev": ...\electrum\electrum\gui\qt\network_dialog.py:457: ResourceWarning: unclosed <socket.socket fd=3276, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('0.0.0.0', 55693), raddr=('127.0.0.1', 9050)> if TorDetector.is_tor_port(net_addr): ResourceWarning: Enable tracemalloc to get the object allocation traceback Diffstat: M electrum/gui/qt/network_dialog.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- DIR diff --git a/electrum/gui/qt/network_dialog.py b/electrum/gui/qt/network_dialog.py t@@ -464,13 +464,13 @@ class TorDetector(QThread): @staticmethod def is_tor_port(net_addr: Tuple[str, int]) -> bool: try: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.settimeout(0.1) - s.connect(net_addr) - # Tor responds uniquely to HTTP-like requests - s.send(b"GET\n") - if b"Tor is not an HTTP Proxy" in s.recv(1024): - return True + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.settimeout(0.1) + s.connect(net_addr) + # Tor responds uniquely to HTTP-like requests + s.send(b"GET\n") + if b"Tor is not an HTTP Proxy" in s.recv(1024): + return True except socket.error: pass return False