Skip to content

Fixed #84 - #85

Merged
fantix merged 2 commits into
masterfrom
t84
Oct 15, 2017
Merged

fantix merged 2 commits into
masterfrom
t84

Conversation

@fantix

@fantix fantix commented Oct 11, 2017

Copy link
Copy Markdown
Member

Don't passthrough task local to spawned tasks which are not immediately joined.

@AmatanHead please review if this works for #84

@fantix fantix added this to the v0.5.x milestone Oct 11, 2017
@AmatanHead

Copy link
Copy Markdown
Contributor

This looks nice. However, what happens if one call .add_done_callback() manually? In this case, task locals would be inherited from wherever .add_done_callback() was called. For example:

...
# We generally don't want to inherit task locals here
asyncio.ensure_future(coro()).add_done_callback(callback)
...

Right now, I see no way to detect such cases. Also, such behaviour makes the whole mechanism even more implicit and unpredictable. So I think, maybe I was too hastened to open #84... Maybe we should just state that task locals inherit from wherever the task was created unless drop_locals() is used?

Also, it would be nice to have a way to check if task locals are enabled ant not inherited. Right now, I use something like assert get_local() is not None. An additional task_local_is_not_inherited assertion can prevent a lot of unexpected things.

@fantix

fantix commented Oct 12, 2017

Copy link
Copy Markdown
Member Author

Yeah I was thinking about temporarily store the context at spawning, and only set it active on add_done_callback instead of get context in the callback, still the issue would be the same - manually adding done callbacks are considered "joining" when it is probably not. I'll update this PR.

@AmatanHead

Copy link
Copy Markdown
Contributor

what about

just state that task locals inherit from wherever the task was created unless drop_locals() is used?

Is it an option?

@fantix

fantix commented Oct 12, 2017

Copy link
Copy Markdown
Member Author

Yes definitely! Please see update.

@AmatanHead AmatanHead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

@fantix

fantix commented Oct 15, 2017

Copy link
Copy Markdown
Member Author

Thx for reviewing and commenting. I'll merge this first and start a new issue for renaming/new package issue, because #84 was actually about managing the inherit behavior but not renaming.

@fantix
fantix merged commit e1f7c14 into master Oct 15, 2017
@fantix
fantix deleted the t84 branch October 15, 2017 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants