Commit 4b95ec8e authored by Jiajun Huang's avatar Jiajun Huang

use with open(...) instead of manually close file

parent 94d95bed
...@@ -138,22 +138,21 @@ def main(path_to_debug_info=None, gdb_argv=None, no_import=False): ...@@ -138,22 +138,21 @@ def main(path_to_debug_info=None, gdb_argv=None, no_import=False):
tempfilename = make_command_file(path_to_debug_info, no_import=no_import) tempfilename = make_command_file(path_to_debug_info, no_import=no_import)
logger.info("Launching %s with command file: %s and gdb_argv: %s", logger.info("Launching %s with command file: %s and gdb_argv: %s",
options.gdb, tempfilename, gdb_argv) options.gdb, tempfilename, gdb_argv)
tempfile_fd = open(tempfilename) with open(tempfilename) as tempfile:
logger.debug('Command file (%s) contains: """\n%s"""', tempfilename, tempfile_fd.read()) logger.debug('Command file (%s) contains: """\n%s"""', tempfilename, tempfile.read())
logger.info("Spawning %s...", options.gdb) logger.info("Spawning %s...", options.gdb)
p = subprocess.Popen([options.gdb, '-command', tempfilename] + gdb_argv) p = subprocess.Popen([options.gdb, '-command', tempfilename] + gdb_argv)
logger.info("Spawned %s (pid %d)", options.gdb, p.pid) logger.info("Spawned %s (pid %d)", options.gdb, p.pid)
while True: while True:
try: try:
logger.debug("Waiting for gdb (pid %d) to exit...", p.pid) logger.debug("Waiting for gdb (pid %d) to exit...", p.pid)
ret = p.wait() ret = p.wait()
logger.debug("Wait for gdb (pid %d) to exit is done. Returned: %r", p.pid, ret) logger.debug("Wait for gdb (pid %d) to exit is done. Returned: %r", p.pid, ret)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
else: else:
break break
logger.debug("Closing temp command file with fd: %s", tempfile_fd) logger.debug("Closing temp command file with fd: %s", tempfile.fileno())
tempfile_fd.close()
logger.debug("Removing temp command file: %s", tempfilename) logger.debug("Removing temp command file: %s", tempfilename)
os.remove(tempfilename) os.remove(tempfilename)
logger.debug("Removed temp command file: %s", tempfilename) logger.debug("Removed temp command file: %s", tempfilename)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment