Empty proofofwork.LogOutput on windows
based on AttributeError in __init__
This commit is contained in:
parent
f4f78a1011
commit
ed7f973b1c
|
@ -37,18 +37,27 @@ class LogOutput(object): # pylint: disable=too-few-public-methods
|
|||
|
||||
def __init__(self, prefix='PoW'):
|
||||
self.prefix = prefix
|
||||
try:
|
||||
sys.stdout.flush()
|
||||
self._stdout = sys.stdout
|
||||
self._stdout_fno = os.dup(sys.stdout.fileno())
|
||||
except AttributeError:
|
||||
# NullWriter instance has no attribute 'fileno' on Windows
|
||||
self._stdout = None
|
||||
else:
|
||||
self._dst, self._filepath = tempfile.mkstemp()
|
||||
|
||||
def __enter__(self):
|
||||
if not self._stdout:
|
||||
return
|
||||
stdout = os.dup(1)
|
||||
os.dup2(self._dst, 1)
|
||||
os.close(self._dst)
|
||||
sys.stdout = os.fdopen(stdout, 'w')
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
if not self._stdout:
|
||||
return
|
||||
sys.stdout.close()
|
||||
sys.stdout = self._stdout
|
||||
sys.stdout.flush()
|
||||
|
|
Reference in New Issue
Block a user