diff --git a/scripts/picard.in b/scripts/picard.in index 741bb1a4f..d6d7f8897 100644 --- a/scripts/picard.in +++ b/scripts/picard.in @@ -10,13 +10,13 @@ except: # noqa: F722 # with minimum chance to fail. import os import sys - import tempfile + from tempfile import NamedTemporaryFile import traceback trace = traceback.format_exc() try: - (fd, logfile) = tempfile.mkstemp(".log", "picard-crash-") - os.write(fd, trace.encode(errors="replace")) - os.close(fd) + with NamedTemporaryFile(suffix='.log', prefix='picard-crash-', delete=False) as f: + f.write(trace.encode(errors="replace")) + logfile = f.name except: # noqa: F722 print("Failed writing log file {0}".format(logfile), file=sys.stderr) logfile = None diff --git a/tagger.py.in b/tagger.py.in index 34270d288..39cbb2548 100644 --- a/tagger.py.in +++ b/tagger.py.in @@ -23,13 +23,13 @@ except SystemExit: except: # noqa: F722 # First try to get traceback information and write it to a log file # with minimum chance to fail. - import tempfile + from tempfile import NamedTemporaryFile import traceback trace = traceback.format_exc() try: - (fd, logfile) = tempfile.mkstemp(".log", "picard-crash-") - os.write(fd, trace.encode(errors="replace")) - os.close(fd) + with NamedTemporaryFile(suffix='.log', prefix='picard-crash-', delete=False) as f: + f.write(trace.encode(errors="replace")) + logfile = f.name except: # noqa: F722 print("Failed writing log file {0}".format(logfile), file=sys.stderr) logfile = None