You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
asyncio.create_subprocess_exec hanging when exception in gathered task #133536
importasyncioasyncdeftask1():
awaitasyncio.create_subprocess_shell(
"ls",
# Any 2 pipes are required to reproducestdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
print("task1 done")
asyncdeftask2():
raiseException("Task 2 failed")
asyncdefmain():
# Either asyncio.gather, asyncio.TaskGroup, or asyncio.as_completed will cause the hangprint("running gather")
awaitasyncio.gather(task1(), task2())
print("running tg")
asyncwithasyncio.TaskGroup() astg:
tg.create_task(task1())
tg.create_task(task2())
print("running as_completed")
forresultinasyncio.as_completed([task1(), task2()]):
awaitresultprint("done")
if__name__=="__main__":
asyncio.run(main())
When awaiting create_subprocess_shell with another task that throws an exception, the subprocess await will hang indefinitely waiting for await transp._wait() in
This is reproducible with either asyncio.gather, asyncio.TaskGroup, or asyncio.as_completed as shown in the example. Interestingly, this requires at least 2 pipes to be attached to the program before this bug will be triggered.
Activity
graingert commentedon May 7, 2025
I think a duplicate of #103847