Closed tlonny closed 11 months ago
Your approach looks good to me - please turn this into a PR :) (with your example as a unit test too!)
@Knio - Thanks for your message. I have a branch with commented code + unit tests but I'm unable to push it:
ERROR: Permission to Knio/dominate.git denied to tlonny.
What do I need to do?
Okay, never mind - I rtfm'd and I've created the PR. Please let me know your thoughts and hope you like it! =D
Hi guys, huge
dominate
fan - thanks for all the work you guys have put in developing it!I had assumed that dominate wouldn't work in an async context due to how tags are globally bound in the
dom_tag._with_contexts
dictionary. I confirmed my hypothesis with this pathological piece of code:You would hope to see:
But instead we see:
I believe the fix for such an issue is to tweak the
_get_thread_context()
function. What I propose is something that looks like this:My idea is that
_get_context_id
will return a new ID for each "execution chain" (idk the correct terminology), which will distinguish between two async functions run concurrently. We add this to thecontext
only if we're currently running in an event loop. I monkeypatched your code with the above and the pathological example above worked as expected.I've never contributed to OSS so LMK if I should turn this into a PR etc.
Thanks!
Tim
P.S. I attach a monkey patch solution for anyone else running into this issue: https://gist.github.com/tlonny/de54ed6ba2481df5f841513d9a9c7ea3