-
-
Notifications
You must be signed in to change notification settings - Fork 330
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
dict don't like that LOCALS_KEY_KI_PROTECTION_ENABLED is not a string... #89
Comments
oh UGH yeah, this is one awful workaround for python limitations colliding with another awful workaround for python limitations. the short answer is that you can work around it by having your trio runner wrap the synthetic function inside a do-nothing pass-through function: async def call(async_fn, *args, **kwargs):
return await async_fn(*args, **kwargs)
trio.run(call, actual_async_fn) (I guess you could sort out your problem with kwargs here too actually, kill 2 birds with 1 stone.) The long answer is: handling control-C correctly is hard, because if it arrives while we're running user code (e.g. that infinite loop that you accidentally wrote, oops) then we want So currently our marker is a non-string object, to make sure that we can't possibly accidentally collide with any real local variable, and this gets injected into the top frame of every (non-system) task. (And this is why adding a trivial wrapper function will let you dodge the issue – we'll inject it into the wrapper function's stack frame, rather than the user code's frame.) You definitely don't want to copy this into the IPython user namespace... I can't actually think of anything that would break, but given the weird stack walking stuff we have to do, letting this variable leak into other parts of the stack is not going to promote stability and predictability. |
Oh, and the reason why assigning to |
(I'm planning to do a blog post soon about trio's control-C handling, it's actually a really interesting topic) |
All make sens, thanks. If you need a proofreader or feedback before publishing I'll be happy to have a look. |
I guess this can be closed, or...? |
Ok, I can take care of that in IPython and have it working... still:
Also you seem to use
locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
in a couple of place.I'm unsure how you can make it work knowing how Python does name lookup in function:
I'm going to guess this is likely done on purpose. Just just trying to understand.
The text was updated successfully, but these errors were encountered: