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'):
|
def __init__(self, prefix='PoW'):
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
sys.stdout.flush()
|
try:
|
||||||
self._stdout = sys.stdout
|
sys.stdout.flush()
|
||||||
self._stdout_fno = os.dup(sys.stdout.fileno())
|
self._stdout = sys.stdout
|
||||||
self._dst, self._filepath = tempfile.mkstemp()
|
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):
|
def __enter__(self):
|
||||||
|
if not self._stdout:
|
||||||
|
return
|
||||||
stdout = os.dup(1)
|
stdout = os.dup(1)
|
||||||
os.dup2(self._dst, 1)
|
os.dup2(self._dst, 1)
|
||||||
os.close(self._dst)
|
os.close(self._dst)
|
||||||
sys.stdout = os.fdopen(stdout, 'w')
|
sys.stdout = os.fdopen(stdout, 'w')
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
if not self._stdout:
|
||||||
|
return
|
||||||
sys.stdout.close()
|
sys.stdout.close()
|
||||||
sys.stdout = self._stdout
|
sys.stdout = self._stdout
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
Reference in New Issue
Block a user