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

restore support for yield unsafe Client context managers and deprecate that support #7987

Conversation

graingert
Copy link
Member

Closes #7984

  • Tests added / passed
  • Passes pre-commit run --all-files

@graingert graingert requested a review from fjetter as a code owner July 12, 2023 11:22
@github-actions
Copy link
Contributor

github-actions bot commented Jul 12, 2023

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

       20 files  ±  0         20 suites  ±0   11h 34m 43s ⏱️ + 4m 23s
  3 718 tests +  2    3 607 ✔️ +  3     106 💤 ±0  5  - 1 
35 962 runs  +20  34 208 ✔️ +21  1 748 💤 ±0  6  - 1 

For more details on these failures, see this check.

Results for commit 5952e30. ± Comparison against base commit 6c37907.

♻️ This comment has been updated with latest results.

@graingert graingert force-pushed the restore-support-for-yield-unsafe-client-context branch from f157a1c to 5952e30 Compare July 12, 2023 13:49
@graingert graingert changed the title restore support for yield unsafe Client context managers restore support for yield unsafe Client context managers and deprecate that support Jul 12, 2023
_current_client.reset(self._previous_as_current)
except ValueError as e:
if not e.args[0].endswith(" was created in a different Context"):
raise
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to add # pragma: nocover or add a test?

raise
warnings.warn(
"It is deprecated to enter and exit the Client context "
"manager from different tasks",
Copy link
Member

Choose a reason for hiding this comment

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

Can we phrase this in a way that tells the user how to replace their anti-pattern?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure how to phrase that, it's usually because someone has used async with Client( inside an async generator, the specific case it's likely to occur is in pytest-asyncio where async fixtures are not run in a way that can support ContextVars, TaskGroups and Timeouts

related discussion is here: https://discuss.python.org/t/preventing-yield-inside-certain-context-managers/1091

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't have any suggestions, either. Let's see if this pops up frequently then and add more context/a link to some Github discussion if need be.

if not e.args[0].endswith(" was created in a different Context"):
raise
warnings.warn(
"It is deprecated to enter and exit the Client context "
Copy link
Member

Choose a reason for hiding this comment

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

See above

_current_client.reset(self._previous_as_current)
except ValueError as e:
if not e.args[0].endswith(" was created in a different Context"):
raise
Copy link
Member

Choose a reason for hiding this comment

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

See above.

distributed/client.py Outdated Show resolved Hide resolved
distributed/client.py Outdated Show resolved Hide resolved
Copy link
Member

@hendrikmakait hendrikmakait left a comment

Choose a reason for hiding this comment

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

Thanks, @graingert!

raise
warnings.warn(
"It is deprecated to enter and exit the Client context "
"manager from different tasks",
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't have any suggestions, either. Let's see if this pops up frequently then and add more context/a link to some Github discussion if need be.

@hendrikmakait hendrikmakait merged commit 9eb6728 into dask:main Jul 27, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

Client context manager teardown error: Token was created in a different Context
2 participants