python-trio / python-trio/trio

CancelScope should ensure that the current task is the same in __enter__() and __exit__()

Open
#1,940 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cancellation
Dominant language
Python
Stars
7.3k
Forks
431
Avg merge
2d 17h
Merged PRs (30d)
6

Description

The following snippet runs without errors and it shouldn't:

import trio


async def enter_scope(scope):
    scope.__enter__()


async def exit_scope(scope):
    scope.__exit__(None, None, None)


async def main():
    scope = trio.CancelScope()
    async with trio.open_nursery() as nursery:
        nursery.start_soon(enter_scope, scope)
    async with trio.open_nursery() as nursery:
        nursery.start_soon(exit_scope, scope)

trio.run(main)

It should check that the current task in __enter__() and __exit__() are the same.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided snippet and then inspect CancelScope.enter() and exit(). The change is complete when entering in one task and exiting in another is rejected, while normal same-task use continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.