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

spawn_system_task should not propagate ContextVar state #289

njsmith opened this Issue Aug 16, 2017 · 2 comments


None yet
2 participants

njsmith commented Aug 16, 2017

Probably we should make spawn_impl have a system_task flag instead of its current ki_protection_enabled flag. We already have to special case init as not inheriting TaskLocals, so this would remove that special case (since init is a system task).


This comment has been minimized.


Fuyukai commented Apr 14, 2018

Is this still relevant, given the ContextVar change? The system task context could potentially be reset to a regular context() rather than a copy_context() (if I understand the issue correctly), otherwise this can be closed.


This comment has been minimized.


njsmith commented Apr 14, 2018

It's still as relevant as it was, just now it applies to ContextVars instead of TaskLocals :-).

The intuition is that a "system task" is a global resource that's not particularly associated with any task, so it shouldn't retain the context where it happened to be spawned. I think I was thinking about this in the context of #303, where the idea is to use system tasks to model the case where you want a single task to be part of multiple parts of the task tree at the same time; in this case it doesn't make sense for ContextVars to be inherited from whichever task happened to start the new one first.

Given how contextvars are more general than a single system, I guess the way to do it would be to stash a copy somewhere of the context that is called with, and then for system tasks copy that instead of the creator's context.

@njsmith njsmith changed the title from spawn_system_task should not propagate TaskLocals to spawn_system_task should not propagate ContextVar state Apr 14, 2018

@Fuyukai Fuyukai closed this in #520 May 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment