Skip to content

Document optional 'task'/'asyncgen' fields in call_exception_handler #21735

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

Merged
merged 2 commits into from
Nov 26, 2020

Conversation

ShaneHarvey
Copy link
Contributor

This change documents the optional "task" field in call_exception_handler. For example I noticed this context while working on Motor:

>>> context
{'message': 'Task was destroyed but it is pending!', 'task': <Task pending name='Task-2' coro=<TestAsyncIOCursor.test_cancelled_error_fetch_next_aggregate() running at /Users/shane/git/motor/test/asyncio_tests/test_asyncio_cursor.py:261> wait_for=<Future finished result={'$clusterTime': {'clusterTime': Timestamp(1596567456, 202), 'signature': {'hash': b'\x00\x00\x0...0\x00\x00\x00', 'keyId': 0}}, 'count': 7, 'ok': 1.0, 'operationTime': Timestamp(1596567456, 202)} created at /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py:418> created at /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/tasks.py:470>, 'source_traceback': [<FrameSummary file setup.py, line 128 in <module>>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/setuptools/__init__.py, line 145 in setup>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/core.py, line 148 in setup>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/dist.py, line 966 in run_commands>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/distutils/dist.py, line 985 in run_command>, <FrameSummary file setup.py, line 120 in run>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/runner.py, line 176 in run>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/suite.py, line 84 in __call__>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/suite.py, line 122 in run>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/case.py, line 736 in __call__>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/case.py, line 676 in run>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/case.py, line 633 in _callTestMethod>, <FrameSummary file /Users/shane/git/motor/test/asyncio_tests/__init__.py, line 48 in __call__>, <FrameSummary file /Users/shane/git/motor/test/test_environment.py, line 283 in wrap>, <FrameSummary file /Users/shane/git/motor/test/asyncio_tests/__init__.py, line 214 in wrapped>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py, line 595 in run_until_complete>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py, line 563 in run_forever>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py, line 1836 in _run_once>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/events.py, line 81 in _run>, <FrameSummary file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/tasks.py, line 470 in wait_for>]}

Most PRs will require an issue number. Trivial changes, like fixing a typo, do not need an issue.

This change seems trivial enough to not need an issue. Let me know if you disagree and I'll create one.

@rougeth
Copy link
Contributor

rougeth commented Aug 4, 2020

Hey @ShaneHarvey, thank you for your PR. There's another key missing at the docs, would you mind adding it as well?

def call_exception_handler(self, context):
"""Call the current event loop's exception handler.
The context argument is a dict containing the following keys:
- 'message': Error message;
- 'exception' (optional): Exception object;
- 'future' (optional): Future instance;
- 'task' (optional): Task instance;
- 'handle' (optional): Handle instance;
- 'protocol' (optional): Protocol instance;
- 'transport' (optional): Transport instance;
- 'socket' (optional): Socket instance;
- 'asyncgen' (optional): Asynchronous generator that caused
the exception.

@ShaneHarvey ShaneHarvey changed the title Document optional "task" field in call_exception_handler Document optional 'task'/'asyncgen' fields in call_exception_handler Aug 4, 2020
@ShaneHarvey
Copy link
Contributor Author

@rougeth thanks for the the quick review. Updated to include the asyncgen field as well.

@asvetlov asvetlov merged commit a1652da into python:master Nov 26, 2020
@bedevere-bot
Copy link

@asvetlov: Please replace # with GH- in the commit message next time. Thanks!

@asvetlov
Copy link
Contributor

Thanks!

@graingert
Copy link
Contributor

this needs a backport to python3.6

@ShaneHarvey
Copy link
Contributor Author

@graingert 3.6 is EOL so it will not be backported: https://devguide.python.org/devcycle/#end-of-life-branches

@graingert
Copy link
Contributor

@graingert 3.6 is EOL so it will not be backported: https://devguide.python.org/devcycle/#end-of-life-branches

Ah sorry I mean 3.6-3.9 are missing this change - so it should be backported to 3.9

@ShaneHarvey
Copy link
Contributor Author

Oh that's a good point. I think a CPython maintainer just needs to add the "needs backport to 3.7/8/9" labels. Either that or one of us can create the backport PR manually.

@AlexWaygood
Copy link
Member

Oh that's a good point. I think a CPython maintainer just needs to add the "needs backport to 3.7/8/9" labels. Either that or one of us can create the backport PR manually.

3.7 & 3.8 are only accepting security-related patches. But 3.9 is still accepting bugfixes and docs patches :)

@AlexWaygood AlexWaygood added the needs backport to 3.9 only security fixes label Jan 20, 2022
@miss-islington
Copy link
Contributor

Thanks @ShaneHarvey for the PR, and @asvetlov for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-30727 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Jan 20, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 20, 2022
vstinner pushed a commit that referenced this pull request Jan 23, 2022
…H-21735) (GH-30727)

(cherry picked from commit a1652da)

Co-authored-by: Shane Harvey <[email protected]>

Co-authored-by: Shane Harvey <[email protected]>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants