]> granicus.if.org Git - python/commitdiff
test_gdb: fix ResourceWarning if the test is interrupted
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 2 Sep 2015 13:46:00 +0000 (15:46 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 2 Sep 2015 13:46:00 +0000 (15:46 +0200)
Lib/test/test_gdb.py

index 193c97afa35467648c915404a0e344e94b0e01d3..a51b552503eb9ac2b2fb5c3b67f057846b35aa09 100644 (file)
@@ -63,9 +63,11 @@ def run_gdb(*args, **env_vars):
     base_cmd = ('gdb', '--batch', '-nx')
     if (gdb_major_version, gdb_minor_version) >= (7, 4):
         base_cmd += ('-iex', 'add-auto-load-safe-path ' + checkout_hook_path)
-    out, err = subprocess.Popen(base_cmd + args,
-        stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env,
-        ).communicate()
+    proc = subprocess.Popen(base_cmd + args,
+                            stdout=subprocess.PIPE,
+                            stderr=subprocess.PIPE, env=env)
+    with proc:
+        out, err = proc.communicate()
     return out.decode('utf-8', 'replace'), err.decode('utf-8', 'replace')
 
 # Verify that "gdb" was built with the embedded python support enabled: