Skip to content

bpo-38785: Prevent asyncio from crashing #17144

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 1 commit into from
Nov 13, 2019

Conversation

asvetlov
Copy link
Contributor

@asvetlov asvetlov commented Nov 13, 2019

if parent __init__ is not called from a constructor of object derived from asyncio.Future

https://bugs.python.org/issue38785

Automerge-Triggered-By: @asvetlov

constructor of object derived from asyncio.Future
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

Note: I would prefer to rename "ENSURE_FUTURE_ALIVE" to "ENSURE_FUTURE_INITIALIZED", but that can be done in a separated PR and it's unrelated to the issue :-)

I tested manually this PR: it does fix https://bugs.python.org/issue38785

Without this PR, the example crash.

With this PR, I get a warning an no crash:

vstinner@apu$ ./python scratch_15.py 
In tratata before
In tratata2 before
Exception in callback <TaskStepMethWrapper object at 0x7f3ccfb878c0>()
handle: <Handle <TaskStepMethWrapper object at 0x7f3ccfb878c0>()>
Traceback (most recent call last):
  File "/home/vstinner/python/master/Lib/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
RuntimeError: Future object is not initialized.
In tratata after

@asvetlov
Copy link
Contributor Author

Yes, RuntimeError was my intention.
CFuture doesn't crash, PyFuture raises the same exception instead of returning None for uninitialized future on fut.get_loop() call.

@miss-islington
Copy link
Contributor

Sorry, I can't merge this PR. Reason: Base branch was modified. Review and try the merge again..

@miss-islington miss-islington merged commit dad6be5 into python:master Nov 13, 2019
@miss-islington
Copy link
Contributor

Thanks @asvetlov for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@asvetlov asvetlov deleted the issue38785 branch November 13, 2019 21:37
@bedevere-bot
Copy link

GH-17147 is a backport of this pull request to the 3.8 branch.

@bedevere-bot
Copy link

GH-17148 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 13, 2019
if parent `__init__` is not called from a constructor of object derived from `asyncio.Future`

https://bugs.python.org/issue38785
(cherry picked from commit dad6be5)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
miss-islington added a commit that referenced this pull request Nov 13, 2019
if parent `__init__` is not called from a constructor of object derived from `asyncio.Future`

https://bugs.python.org/issue38785
(cherry picked from commit dad6be5)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
miss-islington added a commit that referenced this pull request Nov 13, 2019
if parent `__init__` is not called from a constructor of object derived from `asyncio.Future`

https://bugs.python.org/issue38785
(cherry picked from commit dad6be5)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
if parent `__init__` is not called from a constructor of object derived from `asyncio.Future`



https://bugs.python.org/issue38785
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
if parent `__init__` is not called from a constructor of object derived from `asyncio.Future`



https://bugs.python.org/issue38785
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants