Skip to content

ContextTask do not copy parents context  #356

@vytasrgl

Description

@vytasrgl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions