-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
__del__ is not a valid async context #44
Comments
Huh, so just from glancing at the traceback there, it looks like this is a bug in asyncpg. There's just a general fact about all async libraries that it's not safe to call into them from I guess they might happen to get away with it in regular asyncio because by chance, the call stack ultimately hits So: You might be able to work around the issue in your program by making sure that you close connections explicitly (e.g. using The real fix is probably for asyncpg to make their And, even though trio-asyncio is technically in the right here, it's possible we might be forced to figure out a more graceful way to tolerate this kind of situation, if it turns out to be needed for real-world compatibility. |
asyncio's threadsafe version writes a wake-up byte to asyncio's internal buffer, which is required in this situation – garbage collection might be triggered from a different thread, and even if not this could deadlock. |
Going down the rabbit-hole... I just filed:
If we really have to we could make trio-asyncio's version of For one piece of evidence: @touilleMan, are you able to avoid the issue by being more careful to use Another useful piece of evidence would be to check how expensive it would actually be to make |
A microbenchmark on my dev VM reports 49 µsec for By comparison, using asyncio directly, the numbers are 2.3 vs. 4.3 vs. 0.27 µsec. :-/ Edit to add: The 0.27 vs 0.4 µsec are measurement error (obviously). |
Well, sounds like our Did your macrobenchmark just measure the |
I did measure the whole thing:
|
asyncio's |
Well, maybe... |
Part of the problem obviously isn't the queue, but the dance you need to get there.
|
… though we should probably move this somewhere else … |
Well this issue inspired you a lot 😃
Good point, I will modify triopg to have connection&connection pools only work with async context manager. |
With triopg, I sometime encounter this kind of errors:
Basically asyncpg's
Connection
object has a__del__
that wants to do an asyncio operation (so translated by trio-asyncio into doing a trio) but the weird place__del__
execute from doesn't seems to have a trio context :(The text was updated successfully, but these errors were encountered: