Closed isp1356 closed 2 months ago
Thanks for the report. I'm overwhelmed by other tasks and have no idea when I can find time for debugging the issue.
Help is needed for investigating what's going on with multiprocesses.
I don't think running like that (using the low-level asyncio APIs) is something that can work. run_app() expects to be the entry point of your application, so I think your example would make more sense and will be a lot more reliable if you do something more like:
async def test(app):
with concurrent.futures.ProcessPoolExecutor(max_workers=1) as pool:
t = asyncio.get_running_loop().run_in_executor(pool, blocking)
yield
app = aiohttp.web.Application()
app.on_shutdown.append(on_shutdown)
app.cleanup_ctx.append(test)
if __name__ == "__main__":
aiohttp.web.run_app(app)
Long story short
When using a ProcessPoolExecutor from the concurrent python module, the way a
SIGTERM
is handled does not seem to be deterministic. I'm trying to register a shutdown callback viaaiohttp.web.Application.on_shutdown
: sometimes, this callback is called and sometimes not.Expected behaviour
When sending a
SIGTERM
, theon_shutdown
callback in the script below should be always executed.Actual behaviour
When sending a
SIGTERM
, theon_shutdown
callback in the script below is not always executed.Steps to reproduce
SIGTERM
:kill -15 387406
sometimes triggerson_shutdown
and sometimes doesn't.Your environment
aiohttp server: 3.6.0 python: 3.6.9 os: archlinux(5.2.13-arch1-1-ARCH)