Commit aff88c52 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2095 from jdemeyer/atexit_close

Use NamedTemporaryFile instead of mkstemp
parents 223ab47f bb4f0a9c
...@@ -1941,7 +1941,6 @@ PyLocals() ...@@ -1941,7 +1941,6 @@ PyLocals()
################################################################## ##################################################################
import re import re
import atexit
import warnings import warnings
import tempfile import tempfile
import textwrap import textwrap
...@@ -2023,14 +2022,13 @@ class _LoggingState(object): ...@@ -2023,14 +2022,13 @@ class _LoggingState(object):
""" """
def __init__(self): def __init__(self):
self.fd, self.filename = tempfile.mkstemp() f = tempfile.NamedTemporaryFile('r+')
self.file = os.fdopen(self.fd, 'r+') self.file = f
self.filename = f.name
self.fd = f.fileno()
_execute("set logging file %s" % self.filename) _execute("set logging file %s" % self.filename)
self.file_position_stack = [] self.file_position_stack = []
atexit.register(os.close, self.fd)
atexit.register(os.remove, self.filename)
def __enter__(self): def __enter__(self):
if not self.file_position_stack: if not self.file_position_stack:
_execute("set logging redirect on") _execute("set logging redirect on")
......
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