-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Script using ProactorEventLoop does not exit cleanly when subprocesses are spawned. #81562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
On Windows 7, when using ProactorEventLoop, when asyncio.subprocess.terminate is called on the last subprocess when multiple subprocesses are spawned*, the last subprocess will never exit, and the Python interpreter will never exit. Spawning an instance of "TASKKILL /F" to kill the subprocess, and then awaiting asyncio.subprocess.wait is a workaround. Since both "TASKKILL /F" and asyncio.subprocess.terminate ultimately call TerminateProcess, I would expect the same behavior using both (without the need to wait for the subprocess to actually die). I have confirmed this behavior on Python 3.5, 3.6, and 3.7 on both MSVC and MinGW Python (although I most frequently use the latter). Zip file is too large, so I have a GH repo (ready to run) demonstrating this issue: https://github.com/cr1901/proactor An example run looks like the following:$ python3 proactor.py The interpreter hangs after the "Task poller finished." line, which makes me believe that the Python interpreter is trying and failing to cleanup resources for some reason (IOCP never completes?). *Each subprocess is associated with its own coroutine to handle standard output. |
Update: It turns out multiple spawned subprocesses are NOT required. If I replace "(short_fut, _) = await spawn()" with "short_fut = asyncio.ensure_future(asyncio.sleep(4))", the hang still occurs. |
If this issue is fixed by gh-92841, it should be closed. |
@cr1901 Can you check if this is still an issue on main branch and 3.11? It would be better if you can provide a reproducer without involving rust. |
@kumaraditya303 I cannot duplicate this on 3.10.7; I'm not in a position anymore to compile and test the main branch of Python (or 3.11) at present. There is still a minor bug where if I run the script before both
I don't remember the rationale here. I think I was having trouble spawning a python process taking a script as input. I'll see what I can do to make the reproducer Python-only. |
|
I tried your rust reproducer and the bug is fixed in main, 3.11 and 3.10 it doesn't hangs so closing as it is fixed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: