def _check_stream(self):
"""Determines which output stream (stdout, stderr, or custom) to use"""
if self.stream:
try:
if self.stream == 1 and os.isatty(sys.stdout.fileno()):
self._stream_out = sys.stdout.write
self._stream_flush = sys.stdout.flush
elif self.stream == 2 and os.isatty(sys.stderr.fileno()):
self._stream_out = sys.stderr.write
self._stream_flush = sys.stderr.flush
# a fix for IPython notebook "IOStream has no fileno."
except UnsupportedOperation:
if self.stream == 1:
self._stream_out = sys.stdout.write
self._stream_flush = sys.stdout.flush
elif self.stream == 2:
self._stream_out = sys.stderr.write
self._stream_flush = sys.stderr.flush
else:
if self.stream is not None and hasattr(self.stream, 'write'):
self._stream_out = self.stream.write
self._stream_flush = self.stream.flush
else:
print('Warning: No valid output stream.')
评论列表
文章目录