@@ -127,6 +127,7 @@ async def test_outstream(iopub_thread):
127127 assert stream .writable ()
128128
129129
130+ @pytest .mark .skip (reason = "Cannot use a zmq-anyio socket on different threads" )
130131async def test_event_pipe_gc (iopub_thread ):
131132 session = Session (key = b"abc" )
132133 stream = OutStream (
@@ -147,7 +148,7 @@ async def test_event_pipe_gc(iopub_thread):
147148 f : Future = Future ()
148149
149150 try :
150- await iopub_thread ._event_pipe_gc ()
151+ iopub_thread ._event_pipe_gc ()
151152 except Exception as e :
152153 f .set_exception (e )
153154 else :
@@ -164,41 +165,41 @@ async def subprocess_test_echo_watch():
164165
165166 # use PUSH socket to avoid subscription issues
166167 with zmq .Context () as ctx :
167- async with zmq_anyio .Socket (ctx .socket (zmq .PUSH )) as pub :
168- pub .connect (os .environ ["IOPUB_URL" ])
169- iopub_thread = IOPubThread (pub )
170- iopub_thread .start ()
171- stdout_fd = sys .stdout .fileno ()
168+ pub = zmq_anyio .Socket (ctx .socket (zmq .PUSH ))
169+ pub .connect (os .environ ["IOPUB_URL" ])
170+ iopub_thread = IOPubThread (pub )
171+ iopub_thread .start ()
172+ stdout_fd = sys .stdout .fileno ()
173+ sys .stdout .flush ()
174+ stream = OutStream (
175+ session ,
176+ iopub_thread ,
177+ "stdout" ,
178+ isatty = True ,
179+ echo = sys .stdout ,
180+ watchfd = "force" ,
181+ )
182+ save_stdout = sys .stdout
183+ with stream , mock .patch .object (sys , "stdout" , stream ):
184+ # write to low-level FD
185+ os .write (stdout_fd , b"fd\n " )
186+ # print (writes to stream)
187+ print ("print\n " , end = "" )
172188 sys .stdout .flush ()
173- stream = OutStream (
174- session ,
175- iopub_thread ,
176- "stdout" ,
177- isatty = True ,
178- echo = sys .stdout ,
179- watchfd = "force" ,
180- )
181- save_stdout = sys .stdout
182- with stream , mock .patch .object (sys , "stdout" , stream ):
183- # write to low-level FD
184- os .write (stdout_fd , b"fd\n " )
185- # print (writes to stream)
186- print ("print\n " , end = "" )
187- sys .stdout .flush ()
188- # write to unwrapped __stdout__ (should also go to original FD)
189- sys .__stdout__ .write ("__stdout__\n " )
190- sys .__stdout__ .flush ()
191- # write to original sys.stdout (should be the same as __stdout__)
192- save_stdout .write ("stdout\n " )
193- save_stdout .flush ()
194- # is there another way to flush on the FD?
195- fd_file = os .fdopen (stdout_fd , "w" )
196- fd_file .flush ()
197- # we don't have a sync flush on _reading_ from the watched pipe
198- time .sleep (1 )
199- stream .flush ()
200- iopub_thread .stop ()
201- iopub_thread .close ()
189+ # write to unwrapped __stdout__ (should also go to original FD)
190+ sys .__stdout__ .write ("__stdout__\n " )
191+ sys .__stdout__ .flush ()
192+ # write to original sys.stdout (should be the same as __stdout__)
193+ save_stdout .write ("stdout\n " )
194+ save_stdout .flush ()
195+ # is there another way to flush on the FD?
196+ fd_file = os .fdopen (stdout_fd , "w" )
197+ fd_file .flush ()
198+ # we don't have a sync flush on _reading_ from the watched pipe
199+ time .sleep (1 )
200+ stream .flush ()
201+ iopub_thread .stop ()
202+ iopub_thread .close ()
202203
203204
204205@pytest .mark .skipif (sys .platform .startswith ("win" ), reason = "Windows" )
0 commit comments