This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Ignored SIGCHLD causes asyncio.Process.wait to hang forever
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: asyncio.create_subprocess_exec() only works with main event loop
View: 35621
Assigned To: Nosy List: asvetlov, rogpeppe, yselivanov
Priority: normal Keywords:

Created on 2017-11-22 18:32 by rogpeppe, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tst.c rogpeppe, 2017-11-22 18:32 C code that calls python with ignored SIGCHLD
Messages (3)
msg306745 - (view) Author: rogpeppe (rogpeppe) * Date: 2017-11-22 18:32
If some parent process has disabled SIGCHLD, that signal is inherited and stops that signal being delivered, which means that asyncio.Process.wait will never complete.

As an example, the plan9port terminal window, 9term, (https://9fans.github.io/plan9port/man/man1/9term.html) does this, and hence causes async Python processes to hang forever.

Python should probably code defensively against this and ensure that SIGCHLD is enabled regardless. Attached is some C code that demonstrates the issue when the following python code is saved to "tst.py".

    #!/usr/bin/env python3
    import asyncio
    
    async def do_exec():
        cmd = ['echo', 'hello, world']
        process = await asyncio.create_subprocess_exec(*cmd, env={})
        await process.wait()
    
    loop=asyncio.get_event_loop()
    try:
        loop.run_until_complete(do_exec())
    finally:
        loop.close()



demonstration of the issue.
msg308898 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2017-12-21 19:48
Thank for bug report.
Do you know other widespread tools with this problem? 
plan9port sounds too esoteric to me.
msg344278 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-06-02 11:16
#35621 fixes the problem for default ThreadedChildWatcher
History
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76296
2019-06-02 11:16:29asvetlovsetstatus: open -> closed
superseder: asyncio.create_subprocess_exec() only works with main event loop
messages: + msg344278

resolution: duplicate
stage: resolved
2017-12-21 19:48:19asvetlovsetnosy: + asvetlov

messages: + msg308898
versions: + Python 3.6, Python 3.7, - Python 3.5
2017-11-22 18:32:12rogpeppecreate