Skip to content
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

Subprocess on a GunicornWebWorker returns 255 #3333

Open
oux opened this issue Dec 12, 2024 · 1 comment
Open

Subprocess on a GunicornWebWorker returns 255 #3333

oux opened this issue Dec 12, 2024 · 1 comment

Comments

@oux
Copy link

oux commented Dec 12, 2024

from aiohttp import web
import asyncio

app = web.Application()

async def ls():
    stdout = None
    proc = await asyncio.create_subprocess_shell(
        "ls",
        stdout=asyncio.subprocess.PIPE,
    )                                                                                                                                                                                                                                                          
    stdout, _ = await proc.communicate()
    print(f"return code: {proc.returncode}")

asyncio.run(ls())

I run this code in 3 ways:

poetry run gunicorn --worker-class aiohttp.GunicornUVLoopWebWorker test_subprocess:app

return code: 0

poetry run python test_subprocess.py

return code: 0

poetry run gunicorn --worker-class aiohttp.GunicornWebWorker test_subprocess:app

child process pid 339436 exit status already read: will report returncode 255
return code: 255

Workaround to get the right return code with aiohttp.GunicornWebWorker :
Add following line on the script:

asyncio.set_child_watcher(asyncio.FastChildWatcher())

Issue:
asyncio.FastChildWatcher() is marked deprecated and will be removed on python 3.14

@pajod
Copy link
Contributor

pajod commented Dec 13, 2024

Thanks for the quality report!
Related: aio-libs/aiohttp#7038

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants