-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add context-preserving decorator for generators #375
Add context-preserving decorator for generators #375
Conversation
Here is a silly little microbenchmark that I wrote to evaluate a couple different implementations against each other. I wasn't able to discern any difference with it, so maybe it's invalid or there was no meaningful performance difference in my candidates.
|
I suppose? Folks should be aware of the incompatibility with asyncio support I guess.
…pport Add an Eliot-friendly inlineCallbacks-alike decorator. Fixes: ticket:2973 See also upstream effort: itamarst/eliot#375
Probably want documentation for regular generators too. Might take a stab at that as part of verifying the semantics make sense to me. |
--------------------------- | ||
|
||
Eliot provides a decorator that is compatible with Twisted's ``inlineCallbacks`` but which also behaves well with Eliot's actions. | ||
Simply substitute ``eliot.twisted.inline_callbacks`` for ``twisted.internet.defer.inlineCallbacks`` in your code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this documentation is insufficient, since there is also requirement for use_generator_context
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, that's true.
Just figured out how to use magit with github, I think, so will try to make some local changes and push them to your fork/branch. Which might or might not work? I may need to ask you to give me write access to the fork. |
I thiiiink it will just work. Because of that checkbox that defaults to checked that I probably didn't fiddle with. But, annoyingly, it seems like github doesn't tell you if you left it checked or not? Anyway, let me know if you have trouble. |
Question 1: What should we do about regular generators? After playing around with some code, I feel like the behavior when you don't decorate it with (For generator-as-pseudo-coroutine the decorator behavior does make sense.) So perhaps for generators in general this could be solved by documentation ("don't use start_action() around a Thoughts? |
Question 2: Can we get rid of |
Todo: I would like an API to set the sub-context-factory, and for it to blow up if you set it more than once. I can imagine this might cause problems for someone somewhere who wants to use Twisted inlineCallbacks in same program as asyncio and Eliot, but given Eliot userbase is small enough that's a rare use-case we can punt until that's really an issue. |
FWIW, I don't currently have any use-cases involving regular generators. I'm sure they're out there I just haven't bumped into them yet. The codebase I'm working in uses |
Yeah, I realize this is for inlineCallbacks only, but generators are code people use too, and this is effectively a possible solution for that, so want to figure out what to do while we're at it. |
OK, so I guess for this to be merged I'd like:
If you'd rather I do the above let me know. |
Merging to non-master branch in main repo for continued development. |
…orator Add context-preserving decorator for generators
Fixes #259
In addition to a decorator for plain old generators, this also introduces the tiny extra helper necessary to get Twisted's
inlineCallbacks
playing nicely with Eliot. This takes the form of a new decorator that just applies bothinlineCallbacks
and the generator decorator being introduced.Suggestions for better names for any of this welcome. Let me know if there's any other structural work to be done (docs or whatever).
This work made possible by https://leastauthority.com/