diff options
Diffstat (limited to 'Lib/test/support/__init__.py')
-rw-r--r-- | Lib/test/support/__init__.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index c0938d90010..5bd15a2feae 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -706,9 +706,8 @@ def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM): issue if/when we come across it. """ - tempsock = socket.socket(family, socktype) - port = bind_port(tempsock) - tempsock.close() + with socket.socket(family, socktype) as tempsock: + port = bind_port(tempsock) del tempsock return port @@ -1785,10 +1784,11 @@ class _MemoryWatchdog: sys.stderr.flush() return - watchdog_script = findfile("memory_watchdog.py") - self.mem_watchdog = subprocess.Popen([sys.executable, watchdog_script], - stdin=f, stderr=subprocess.DEVNULL) - f.close() + with f: + watchdog_script = findfile("memory_watchdog.py") + self.mem_watchdog = subprocess.Popen([sys.executable, watchdog_script], + stdin=f, + stderr=subprocess.DEVNULL) self.started = True def stop(self): |