Incomplete async support? #257
oliverhaas
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
For vaguely related reasons I looked through the internals of pghistory (great package btw 😃) last week, and since I have the topic of async django on the back of my mind more and more, I noticed the use of
threading.localand was trying to wrap my head around how or how well async is supported in pghistory.I found this issue #217, which supposedly fixes async support, but my initial thought was that any solution with
threading.localinstead ofContextVarwould be incomplete, but I'm definitely not well versed in the topic.I think pghistory supports async only as far as one does not have real concurrency with async and "accidentally" still serializes due to
async_to_sync / sync_to_async, but breaks otherwise. The failure mode is actually not intuitive, apparently since merging the context and event loop and thread interaction. Here a simple test repro oliverhaas#2Obviously this is not a realistic django request cycle, and I know there are a lot of cases where the context would just work, but it also looks to me that there are big gaps.
I'm still not certain about a lot of things and I still wouldn't be surprised if I was missing something obvious, but in any case I wanted to take a small step and ask here whether someone has more information. If I'm correct I would be looking forward into making a PR with a
ContextVarsolution (so the internal parts), plus probably a second PR for stuff like async middleware.Beta Was this translation helpful? Give feedback.
All reactions