@@ -286,6 +286,69 @@ async def main():
286
286
]
287
287
self .assertEqual (stack_trace , expected_stack_trace )
288
288
289
+ @unittest .skipIf (sys .platform != "darwin" and sys .platform != "linux" ,
290
+ "Test only runs on Linux and MacOS" )
291
+ @unittest .skipIf (sys .platform == "linux" and not PROCESS_VM_READV_SUPPORTED ,
292
+ "Test only runs on Linux with process_vm_readv support" )
293
+ def test_async_staggered_race_remote_stack_trace (self ):
294
+ # Spawn a process with some realistic Python code
295
+ script = textwrap .dedent ("""\
296
+ import asyncio.staggered
297
+ import time
298
+ import sys
299
+
300
+ async def deep():
301
+ await asyncio.sleep(0)
302
+ fifo_path = sys.argv[1]
303
+ with open(fifo_path, "w") as fifo:
304
+ fifo.write("ready")
305
+ time.sleep(10000)
306
+
307
+ async def c1():
308
+ await asyncio.sleep(0)
309
+ await deep()
310
+
311
+ async def c2():
312
+ await asyncio.sleep(10000)
313
+
314
+ async def main():
315
+ await asyncio.staggered.staggered_race(
316
+ [c1, c2],
317
+ delay=None,
318
+ )
319
+
320
+ asyncio.run(main())
321
+ """ )
322
+ stack_trace = None
323
+ with os_helper .temp_dir () as work_dir :
324
+ script_dir = os .path .join (work_dir , "script_pkg" )
325
+ os .mkdir (script_dir )
326
+ fifo = f"{ work_dir } /the_fifo"
327
+ os .mkfifo (fifo )
328
+ script_name = _make_test_script (script_dir , 'script' , script )
329
+ try :
330
+ p = subprocess .Popen ([sys .executable , script_name , str (fifo )])
331
+ with open (fifo , "r" ) as fifo_file :
332
+ response = fifo_file .read ()
333
+ self .assertEqual (response , "ready" )
334
+ stack_trace = get_async_stack_trace (p .pid )
335
+ except PermissionError :
336
+ self .skipTest (
337
+ "Insufficient permissions to read the stack trace" )
338
+ finally :
339
+ os .remove (fifo )
340
+ p .kill ()
341
+ p .terminate ()
342
+ p .wait (timeout = SHORT_TIMEOUT )
343
+
344
+ # sets are unordered, so we want to sort "awaited_by"s
345
+ stack_trace [2 ].sort (key = lambda x : x [1 ])
346
+
347
+ expected_stack_trace = [
348
+ ['deep' , 'c1' , 'run_one_coro' ], 'Task-2' , [[['main' ], 'Task-1' , []]]
349
+ ]
350
+ self .assertEqual (stack_trace , expected_stack_trace )
351
+
289
352
@unittest .skipIf (sys .platform != "darwin" and sys .platform != "linux" ,
290
353
"Test only runs on Linux and MacOS" )
291
354
@unittest .skipIf (sys .platform == "linux" and not PROCESS_VM_READV_SUPPORTED ,
0 commit comments