File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 1111import sys
1212import time
1313from getpass import getpass
14+ from io import FileIO
15+ from io import TextIOWrapper
16+ from logging import StreamHandler
1417
1518import zmq
1619from ipykernel .kernelapp import IPKernelApp
@@ -553,6 +556,20 @@ def urls(key):
553556 self .session , iopub_socket , u'stderr'
554557 )
555558 sys .stderr .topic = cast_bytes ('engine.%i.stderr' % self .id )
559+
560+ # copied from ipykernel 6, which captures sys.__stderr__ at the FD-level
561+ if getattr (sys .stderr , "_original_stdstream_copy" , None ) is not None :
562+ for handler in self .log .handlers :
563+ if isinstance (handler , StreamHandler ) and (
564+ handler .stream .buffer .fileno () == 2
565+ ):
566+ self .log .debug (
567+ "Seeing logger to stderr, rerouting to raw filedescriptor."
568+ )
569+
570+ handler .stream = TextIOWrapper (
571+ FileIO (sys .stderr ._original_stdstream_copy , "w" )
572+ )
556573 if self .display_hook_factory :
557574 sys .displayhook = self .display_hook_factory (self .session , iopub_socket )
558575 sys .displayhook .topic = cast_bytes ('engine.%i.execute_result' % self .id )
You can’t perform that action at this time.
0 commit comments