File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,8 @@ def process_exited(self):
96
96
returncode = self ._transport .get_returncode ()
97
97
while self ._waiters :
98
98
waiter = self ._waiters .popleft ()
99
- waiter .set_result (returncode )
99
+ if not waiter .cancelled ():
100
+ waiter .set_result (returncode )
100
101
101
102
102
103
class Process :
Original file line number Diff line number Diff line change @@ -223,6 +223,34 @@ def len_message(message):
223
223
self .assertEqual (output .rstrip (), b'3' )
224
224
self .assertEqual (exitcode , 0 )
225
225
226
+ def test_cancel_process_wait (self ):
227
+ # Issue #23140: cancel Process.wait()
228
+
229
+ @asyncio .coroutine
230
+ def wait_proc (proc , event ):
231
+ event .set ()
232
+ yield from proc .wait ()
233
+
234
+ @asyncio .coroutine
235
+ def cancel_wait ():
236
+ proc = yield from asyncio .create_subprocess_exec (
237
+ * PROGRAM_BLOCKED ,
238
+ loop = self .loop )
239
+
240
+ # Create an internal future waiting on the process exit
241
+ event = asyncio .Event (loop = self .loop )
242
+ task = self .loop .create_task (wait_proc (proc , event ))
243
+ yield from event .wait ()
244
+
245
+ # Cancel the future
246
+ task .cancel ()
247
+
248
+ # Kill the process and wait until it is done
249
+ proc .kill ()
250
+ yield from proc .wait ()
251
+
252
+ self .loop .run_until_complete (cancel_wait ())
253
+
226
254
227
255
if sys .platform != 'win32' :
228
256
# Unix
You can’t perform that action at this time.
0 commit comments