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

ContextTask do not copy parents context #356

Open
vytasrgl opened this issue Aug 4, 2022 · 3 comments
Open

ContextTask do not copy parents context #356

vytasrgl opened this issue Aug 4, 2022 · 3 comments

Comments

@vytasrgl
Copy link

vytasrgl commented Aug 4, 2022

Using ContextTask class currently creates empty context for each of the tasks. The desirable behavior would be that child tasks would have access to the parent task context.

Right now it seems its hard to implement the way that would solve it only by modifying the ContextTask code, however it can be solved by running task creation in the parent's context:

        # Create a new task. Putting it on the ready queue
        def new_task(coro):
            # Children should be created with parent context if any
            nonlocal current
            if current and current._context:
                task = current._context.run(taskcls, coro)
            else:
                task = taskcls(coro)
            tasks[task.id] = task
            reschedule_task(task)
            for a in _activations:
                a.created(task)
            return task
@dabeaz
Copy link
Owner

dabeaz commented Aug 12, 2022

Just to make sure that I understand this, the primary issue is that new tasks aren't created within the context of the parent task?

All things equal, I don't want the Curio core to be dependent on contextvars. However, it may be possible to restructure things slightly to make this possible. I will investigate.

@vytasrgl
Copy link
Author

Yes, indeed, the issue that the new tasks are created outside current context, so those tasks cant access the parent context.

I endup using this patch which does not incluide too much dependancies in the core, but still there are probably better ways to do this.
hansonrobotics@1c56eaf

@dabeaz
Copy link
Owner

dabeaz commented Aug 13, 2022

I made a modification to have the parent task passed to the Task.__init__() method. Let me know if this addresses the problem.

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