ipykernel unconditionally calls sys.stdout.flush() and sys.stderr.flush(). This is a problem when either sys.stdout or sys.stderr is None, such as in pythonw.exe on windows, or Pyinstaller's windowed mode. All of these checks should be garded with a not-None check.