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
Bind logger and waninigs modules for asyncio __del__ methods #69261
Comments
See aio-libs/aiohttp#497 for the reason. Desctructors and descendant code ( |
I don't like such "hacks". IMHO It's too late to try to log errors, to execute code to cleanup objects, etc. You should try to implement something in aiohttp or even in the application to cleanup objects at exit. For example, it's probably wrong if you still have tasks when the event loop is closed. Especially if tasks are still pending. See this part of the doc which lists "pending tasks at exit": For "exceptions never consumed", I proposed a different enhancement in asyncio directly: What do you think? |
The problem is for client API. For server I have more control and implemented checks like you suggest. For for client lazy user writes floppy code like: client = aiohttp.ClientSession()
resp = yield from client.get(url)
text = yield from resp.text() Client is closed by GC, at the moment is not determined is loop has been closed or not (GC releases object in non-determenistic way). So without changes I just cannot use It's not only aiohttp issue but we should get rid of We have
|
Yes, the approach use hackery shadows for binding global variables on shutdown stage. The problem is: I want to inform users about unclosed resources. On shutdown logger and warnings modules may be destroyed at the moment of del call, so As an option we can add atexit handler to store shutdown flag into loop object (I don't know other way to get info is interpreter in shutdown or not). According to the flag we can eihter print some short text about non-closed resources or raise proper ResourceWarning along with comprehensive logging with stacktrace if PYTHONASYNCIO is on. Maybe I've missed something and you can suggest better solution. |
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: