Skip to content

Commit

Permalink
Merge pull request #344 from jenshnielsen/fix/sys_std_out_is_None
Browse files Browse the repository at this point in the history
Check that sys.stdout/err is not None before flushing
  • Loading branch information
Carreau authored Sep 21, 2018
2 parents 46064b7 + ab24cf9 commit acb1e39
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,17 @@ def init_io(self):
"""Redirect input streams and set a display hook."""
if self.outstream_class:
outstream_factory = import_item(str(self.outstream_class))
sys.stdout.flush()
if sys.stdout is not None:
sys.stdout.flush()

e_stdout = None if self.quiet else sys.__stdout__
e_stderr = None if self.quiet else sys.__stderr__

sys.stdout = outstream_factory(self.session, self.iopub_thread,
u'stdout',
echo=e_stdout)
sys.stderr.flush()
if sys.stderr is not None:
sys.stderr.flush()
sys.stderr = outstream_factory(self.session, self.iopub_thread,
u'stderr',
echo=e_stderr)
Expand Down

0 comments on commit acb1e39

Please sign in to comment.