-
Notifications
You must be signed in to change notification settings - Fork 283
WIP: add lifespan support (monkay based) #570
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
base: main
Are you sure you want to change the base?
Conversation
Changes: - add lifespan support via monkay.asgi - Bump minimum python version (near EOL, needs discussion)
07ab334 to
fa811a6
Compare
|
if needed, I can readd python 3.9 support in monkay |
|
No problem with Python 3.10 as a minimum version. |
|
I'm not sure if the lifespan cleanup is going right :(. When using --noreload I do see |
|
not sure where the bug results from. I think twisted ignores the return value despite documented |
|
I rewrote the code for test purposes: def kill_all_applications(self):
"""
Kills all application coroutines before reactor exit.
"""
# Make Twisted wait until they're all dead and cleanup lifespan
async def cleanup():
# Send cancel to all coroutines
wait_for = []
for details in self.connections.values():
application_instance = details["application_instance"]
if not application_instance.done():
application_instance.cancel()
wait_for.append(application_instance)
logger.info("Killed %i pending application instances", len(wait_for))
try:
await asyncio.gather(*wait_for)
finally:
if self.lifespan_context:
await self.lifespan_context.__aexit__()
return defer.Deferred.fromFuture(cleanup())Effect: silence (no info output). Seemingly they ignore the return value |
def kill_all_applications(self):
"""
Kills all application coroutines before reactor exit.
"""
# Make Twisted wait until they're all dead and cleanup lifespan
async def cleanup():
# Send cancel to all coroutines
wait_for = []
for details in self.connections.values():
application_instance = details["application_instance"]
if not application_instance.done():
application_instance.cancel()
wait_for.append(application_instance)
logger.info("Killed %i pending application instances", len(wait_for))
try:
await asyncio.gather(*wait_for)
finally:
if self.lifespan_context:
await self.lifespan_context.__aexit__()
reactor._asyncioEventloop.run_until_complete(cleanup())Gives me a resource warning |
|
Found a solution. But I doubt that the kill_app code is working. |
Changes: