Skip to content
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

Task factory used in example #21

Open
nikhilk opened this issue Jul 7, 2018 · 1 comment
Open

Task factory used in example #21

nikhilk opened this issue Jul 7, 2018 · 1 comment

Comments

@nikhilk
Copy link

nikhilk commented Jul 7, 2018

Is the simple task_factory used in the PoC example the best choice?

It seems you'd want the request id to propagate to child tasks created within request processing. So one of the other two task factories seem more appropriate. Likely the copying one.

Is that correct understanding? I wonder if the example should be updated.

Side note -- this functionality is super useful, and should be more deeply merged into asyncio IMO.

@argaen
Copy link
Contributor

argaen commented Sep 10, 2018

Hey @nikhilk sorry for the delay, been on annual leave for couple of months :).

With the simple task factory, a dict is used and the dict is propagated from parent to child. A simple child_context = parent_context is done. This has the side effect that if you update an already existing key in the child, the parent will also be affected because it is the same object. If you don't want this behavior, you can set the copy_context variable to True and then deepcopy will be use (with the extra overhead this implies).

Side note -- this functionality is super useful, and should be more deeply merged into asyncio IMO.

Glad you like it, it's proven very useful for us and it is really simple to use. In Python 3.7 you can use contextvars module (pep-567)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants