@@ -10,6 +10,7 @@ cdef class UVProcess(UVHandle):
10
10
self ._fds_to_close = set ()
11
11
self ._preexec_fn = None
12
12
self ._restore_signals = True
13
+ self .context = Context_CopyCurrent()
13
14
14
15
cdef _close_process_handle(self ):
15
16
# XXX: This is a workaround for a libuv bug:
@@ -364,7 +365,8 @@ cdef class UVProcessTransport(UVProcess):
364
365
UVProcess._on_exit(self , exit_status, term_signal)
365
366
366
367
if self ._stdio_ready:
367
- self ._loop.call_soon(self ._protocol.process_exited)
368
+ self ._loop.call_soon(self ._protocol.process_exited,
369
+ context = self .context)
368
370
else :
369
371
self ._pending_calls.append((_CALL_PROCESS_EXITED, None , None ))
370
372
@@ -383,14 +385,16 @@ cdef class UVProcessTransport(UVProcess):
383
385
384
386
cdef _pipe_connection_lost(self , int fd, exc):
385
387
if self ._stdio_ready:
386
- self ._loop.call_soon(self ._protocol.pipe_connection_lost, fd, exc)
388
+ self ._loop.call_soon(self ._protocol.pipe_connection_lost, fd, exc,
389
+ context = self .context)
387
390
self ._try_finish()
388
391
else :
389
392
self ._pending_calls.append((_CALL_PIPE_CONNECTION_LOST, fd, exc))
390
393
391
394
cdef _pipe_data_received(self , int fd, data):
392
395
if self ._stdio_ready:
393
- self ._loop.call_soon(self ._protocol.pipe_data_received, fd, data)
396
+ self ._loop.call_soon(self ._protocol.pipe_data_received, fd, data,
397
+ context = self .context)
394
398
else :
395
399
self ._pending_calls.append((_CALL_PIPE_DATA_RECEIVED, fd, data))
396
400
@@ -517,6 +521,7 @@ cdef class UVProcessTransport(UVProcess):
517
521
518
522
cdef _call_connection_made(self , waiter):
519
523
try :
524
+ # we're always called in the right context, so just call the user's
520
525
self ._protocol.connection_made(self )
521
526
except (KeyboardInterrupt , SystemExit ):
522
527
raise
@@ -556,7 +561,9 @@ cdef class UVProcessTransport(UVProcess):
556
561
self ._finished = 1
557
562
558
563
if self ._stdio_ready:
559
- self ._loop.call_soon(self ._protocol.connection_lost, None )
564
+ # copy self.context for simplicity
565
+ self ._loop.call_soon(self ._protocol.connection_lost, None ,
566
+ context = self .context)
560
567
else :
561
568
self ._pending_calls.append((_CALL_CONNECTION_LOST, None , None ))
562
569
@@ -572,6 +579,7 @@ cdef class UVProcessTransport(UVProcess):
572
579
new_MethodHandle1(self ._loop,
573
580
" UVProcessTransport._call_connection_made" ,
574
581
< method1_t> self ._call_connection_made,
582
+ None , # means to copy the current context
575
583
self , waiter))
576
584
577
585
@staticmethod
@@ -598,6 +606,8 @@ cdef class UVProcessTransport(UVProcess):
598
606
if handle._init_futs:
599
607
handle._stdio_ready = 0
600
608
init_fut = aio_gather(* handle._init_futs)
609
+ # add_done_callback will copy the current context and run the
610
+ # callback within the context
601
611
init_fut.add_done_callback(
602
612
ft_partial(handle.__stdio_inited, waiter))
603
613
else :
@@ -606,6 +616,7 @@ cdef class UVProcessTransport(UVProcess):
606
616
new_MethodHandle1(loop,
607
617
" UVProcessTransport._call_connection_made" ,
608
618
< method1_t> handle._call_connection_made,
619
+ None , # means to copy the current context
609
620
handle, waiter))
610
621
611
622
return handle
0 commit comments