When an `StopIteration` raises into `asyncio.Future`, this will cause
a thread to hang. This commit address this by not raising an exception
and silently transforming the `StopIteration` with a `RuntimeError`,
which the caller can reconstruct from `fut.exception().__cause__`
asyncio.get_event_loop() now always return either running event loop or
the result of get_event_loop_policy().get_event_loop() call. The latter
should now raise an RuntimeError if no current event loop was set
instead of creating and setting a new event loop.
It affects also a number of asyncio functions and constructors which
call get_event_loop() implicitly: ensure_future(), shield(), gather(),
etc.
DeprecationWarning is no longer emitted if there is no running event loop but
the current event loop was set.
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
After a long deliberation we ended up feeling that the message argument for Future.cancel(), added in 3.9, was a bad idea, so we're deprecating it in 3.11 and plan to remove it in 3.13.
asyncio.get_event_loop() emits now a deprecation warning when it creates a new event loop.
In future releases it will became an alias of asyncio.get_running_loop().
This is my first issue!
So, if there's anything wrong, please tell me!
Also, thank you always for all the contributors!
Automerge-Triggered-By: GH:asvetlov
When an asyncio.Task is cancelled, the exception traceback now
starts with where the task was first interrupted. Previously,
the traceback only had "depth one."
Specifically, it's not possible to subclass Task/Future classes
and override the following methods:
* Future._schedule_callbacks
* Task._step
* Task._wakeup
The asyncio/compat.py file was written to support Python < 3.5 and
Python < 3.5.2. But Python 3.5 doesn't accept bugfixes anymore, only
security fixes. There is no more need to backport bugfixes to Python
3.5, and so no need to have a single code base for Python 3.5, 3.6
and 3.7.
Say hello (again) to "async" and "await", who became real keywords in
Python 3.7 ;-)
This implementation provides additional 10-20% speed boost for
asyncio programs.
The patch also fixes _asynciomodule.c to use Arguments Clinic, and
makes '_schedule_callbacks' an overridable method (as it was in 3.5).
This is now an official "protected" API that can be used to write
classes that are duck-type-compatible with Future without subclassing
it. (For that purpose I also changed isinstance(result, Future) to
check for this attribute instead.)
Hopefully Amber Brown can use this to make Twisted.Deferred compatible
with asyncio.Future.
Tests and docs are TBD.