Commit Graph

139 Commits

Author SHA1 Message Date
Serhiy Storchaka 172c0f2752
bpo-39529: Deprecate creating new event loop in asyncio.get_event_loop() (GH-23554)
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().
2021-04-25 13:40:44 +03:00
Richard Kojedzinszky 17ef4319a3
bpo-41891: ensure asyncio.wait_for waits for task completion (#22461) 2020-12-18 09:26:04 -08:00
Serhiy Storchaka 8a62887dfb
bpo-42582: Remove asyncio._all_tasks_compat(). (GH-23664)
It was used to implement now removed asyncio.Task.all_tasks().
2020-12-06 18:54:33 +02:00
Yurii Karabas e4fe303b8c
bpo-42392: Remove loop parameter from asyncio.tasks and asyncio.subprocess (GH-23521) 2020-11-28 10:21:17 +02:00
Yurii Karabas 0ec34cab9d
bpo-42392: Remove loop parameter form asyncio locks and Queue (#23420)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2020-11-24 20:08:54 +02:00
Diogo Dutra 7e5ef0a571
bpo-42140: Improve asyncio.wait function (GH-22938)
# Improve asyncio.wait function

The original code creates the futures set two times.
We can create this set before, avoiding the second creation.

This new behaviour [breaks the aiokafka library](https://github.com/aio-libs/aiokafka/pull/672), because it gives an iterator to that function, so the second iteration become empty.

Automerge-Triggered-By: GH:1st1
2020-11-10 14:12:52 -08:00
Jakub Stasiak 3d86d090dc
bpo-42230: Improve asyncio documentation regarding accepting sets vs iterables (GH-23073)
People call wait() and as_completed() with various non-set iterables,
a list should be the most common but there are others as well[1].

Considering typeshed also documents wait()[2] and as_completed()[3]
as accepting arbitrary iterables I think it's a good idea to document
the status quo better.

[1] https://github.com/aio-libs/aiokafka/pull/672
[2] 620989bac5/stdlib/3/asyncio/tasks.pyi (L161)
[3] 620989bac5/stdlib/3/asyncio/tasks.pyi (L40)
2020-11-02 12:56:35 +02:00
Elvis Pranskevichus a2118a1462
bpo-37658: Fix asyncio.wait_for() to respect waited task status (#21894)
Currently, if `asyncio.wait_for()` itself is cancelled it will always
raise `CancelledError` regardless if the underlying task is still
running.  This is similar to a race with the timeout, which is handled
already.
2020-08-26 09:42:45 -07:00
Elvis Pranskevichus c517fc7121
bpo-32751: Wait for task cancel in asyncio.wait_for() when timeout <= 0 (#21895)
When I was fixing bpo-32751 back in GH-7216 I missed the case when
*timeout* is zero or negative.  This takes care of that.

Props to @aaliddell for noticing the inconsistency.
2020-08-26 09:42:22 -07:00
Vinay Sharma d42528a3a2
bpo-37703: improve asyncio.gather documentation regarding cancellation (GH-15312)
These changes updates the doc to comprehensively mention the behaviour of gather.cancel()

Automerge-Triggered-By: @asvetlov
2020-07-20 01:42:57 -07:00
Rémi Lapeyre 004e64e805
bpo-40967: Remove deprecated asyncio.Task.current_task() and asyncio.Task.all_tasks() (GH-20874) 2020-07-01 20:41:21 -07:00
Chris Jerdonek da742ba826
bpo-31033: Improve the traceback for cancelled asyncio tasks (GH-19951)
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."
2020-05-17 22:47:31 -07:00
Chris Jerdonek 1ce5841eca
bpo-31033: Add a msg argument to Future.cancel() and Task.cancel() (GH-19979) 2020-05-15 16:55:50 -07:00
romasku 382a5635bd
bpo-40607: Reraise exception during task cancelation in asyncio.wait_for() (GH-20054)
Currently, if asyncio.wait_for() timeout expires, it cancels
inner future and then always raises TimeoutError. In case
those future is task, it can handle cancelation mannually,
and those process can lead to some other exception. Current
implementation silently loses thoses exception.

To resolve this, wait_for will check was the cancelation
successfull or not. In case there was exception, wait_for
will reraise it.

Co-authored-by: Roman Skurikhin <roman.skurikhin@cruxlab.com>
2020-05-15 13:12:05 -07:00
Kyle Stanley 89aa7f0ede bpo-34790: Implement deprecation of passing coroutines to asyncio.wait() (GH-16977) 2019-12-30 13:50:19 +02:00
Batuhan Taşkaya dec367261e bpo-38978: Implement __class_getitem__ for asyncio objects (GH-17491)
https://bugs.python.org/issue38978
2019-12-07 03:05:07 -08:00
Yury Selivanov edad4d89e3 bpo-38248: Fix inconsistent immediate asyncio.Task cancellation (GH-16330) 2019-09-25 03:32:08 -07:00
Andrew Svetlov a488879cba
bpo-36373: Deprecate explicit loop in task and subprocess API (GH-16033) 2019-09-12 15:40:40 +03:00
Andrew Svetlov 65aa64fae8 bpo-36607: Eliminate RuntimeError raised by asyncio.all_tasks() (GH-13971)
If internal tasks weak set is changed by another thread during iteration.



https://bugs.python.org/issue36607
2019-06-11 08:27:30 -07:00
Alex Grönholm 98ef92002e bpo-36999: Add asyncio.Task.get_coro() (GH-13680)
https://bugs.python.org/issue36999
2019-05-30 08:30:09 -07:00
Yury Selivanov 431b540bf7
bpo-32528: Make asyncio.CancelledError a BaseException. (GH-13528)
This will address the common mistake many asyncio users make:
an "except Exception" clause breaking Tasks cancellation.

In addition to this change, we stop inheriting asyncio.TimeoutError
and asyncio.InvalidStateError from their concurrent.futures.*
counterparts.  There's no point for these exceptions to share the
inheritance chain.

In 3.9 we'll focus on implementing supervisors and cancel scopes,
which should allow better handling of all exceptions, including
SystemExit and KeyboardInterrupt
2019-05-27 14:45:12 +02:00
Matthias Bussonnier d0ebf13e50 bpo-36932: use proper deprecation-removed directive (GH-13349)
.. And update some deprecation warnings with version numbers.




https://bugs.python.org/issue36932
2019-05-20 23:20:10 -07:00
Andrew Svetlov 68b34a7204 bpo-36921: Deprecate @coroutine for sake of async def (GH-13346)
The second attempt. Now deprecate `@coroutine` only, keep `yield from fut` as is.


https://bugs.python.org/issue36921
2019-05-16 07:52:10 -07:00
Romain Picard b35acc5b3a bpo-35125: remove inner callback on outer cancellation in asyncio shield (GH-10340)
When the future returned by shield is cancelled, its completion callback of the
inner future is not removed. This makes the callback list of inner inner future
grow each time a shield is created and cancelled.

This change unregisters the callback from the inner future when the outer
future is cancelled.



https://bugs.python.org/issue35125
2019-05-07 11:58:24 -07:00
Zackery Spytz 4737b923df bpo-24638: Improve the error message in asyncio.ensure_future() (#12848) 2019-05-03 11:35:25 -04:00
gescheit c1964e9e21 bpo-36613: call remove_done_callback if exception (GH-12800)
Call remove_done_callback() in finally block.


https://bugs.python.org/issue36613
2019-05-03 08:18:02 -07:00
Inada Naoki c5c6cdada3 asyncio: PendingDeprecationWarning -> DeprecationWarning (GH-12494)
`Task.current_task()` and `Task.all_tasks()` will be removed in 3.9.
2019-03-22 04:07:32 -07:00
Andrew Svetlov 97cf082872 bpo-34970: Protect tasks weak set manipulation in asyncio.all_tasks() (GH-9837)
https://bugs.python.org/issue34970
2018-10-13 11:12:40 -07:00
Yury Selivanov fad6af2744
asyncio/docs: Replace Python 4.0 -> 3.10 (GH-9579) 2018-09-25 17:44:52 -04:00
João Júnior 558c49bcf3 bpo-34728: Remove deprecate *loop* argument in asyncio.sleep (GH-9415)
* Insert the warn in the asyncio.sleep when the loop argument is used

* Insert the warn in the asyncio.wait and asyncio.wait_for when the loop argument is used

* Better format of the code

* Add news file

* change calls for get_event_loop() to calls for get_running_loop()

* Change message to be more clear in News

* Improve the comments in test_tasks
2018-09-24 05:51:22 -04:00
Andrew Svetlov 0baa72f4b2
bpo-34622: Extract asyncio exceptions into a separate module (GH-9141) 2018-09-11 10:13:04 -07:00
Alex Grönholm cca4eec3c0 bpo-34270: Make it possible to name asyncio tasks (GH-8547)
Co-authored-by: Antti Haapala <antti.haapala@anttipatterns.com>
2018-08-08 17:06:47 -04:00
Elvis Pranskevichus e2b340ab41 bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216)
Currently, asyncio.wait_for(fut), upon reaching the timeout deadline,
cancels the future and returns immediately.  This is problematic for
when *fut* is a Task, because it will be left running for an arbitrary
amount of time.  This behavior is iself surprising and may lead to
related bugs such as the one described in bpo-33638:

    condition = asyncio.Condition()
    async with condition:
        await asyncio.wait_for(condition.wait(), timeout=0.5)

Currently, instead of raising a TimeoutError, the above code will fail
with `RuntimeError: cannot wait on un-acquired lock`, because
`__aexit__` is reached _before_ `condition.wait()` finishes its
cancellation and re-acquires the condition lock.

To resolve this, make `wait_for` await for the task cancellation.
The tradeoff here is that the `timeout` promise may be broken if the
task decides to handle its cancellation in a slow way.  This represents
a behavior change and should probably not be back-patched to 3.6 and
earlier.
2018-05-29 17:31:01 -04:00
Yury Selivanov 863b674909
bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209) 2018-05-29 17:20:02 -04:00
Yury Selivanov 416c1ebd98
bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. (GH-7174) 2018-05-28 17:54:02 -04:00
jimmylai e549c4be5f bpo-33505: Optimize asyncio.ensure_future by reordering if conditions (GH-6836) 2018-05-28 12:42:05 -04:00
Serhiy Storchaka 6655354afc
bpo-33584: Fix several minor bugs in asyncio. (GH-7003)
Fix the following bugs in the C implementation:

* get_future_loop() silenced all exceptions raised when look up the get_loop
  attribute, not just an AttributeError.
* enter_task() silenced all exceptions raised when look up the current task,
  not just a KeyError.
* repr() was called for a borrowed link in enter_task() and task_step_impl().
* str() was used instead of repr() in formatting one error message (in
  Python implementation too).
* There where few reference leaks in error cases.
2018-05-20 16:30:31 +03:00
Yury Selivanov 22feeb88b4
bpo-32643: Drop support for a few private Task and Future APIs. (#5293)
Specifically, it's not possible to subclass Task/Future classes
and override the following methods:

* Future._schedule_callbacks
* Task._step
* Task._wakeup
2018-01-24 11:31:01 -05:00
Yury Selivanov f23746a934
bpo-32436: Implement PEP 567 (#5027) 2018-01-22 19:11:18 -05:00
Yury Selivanov 0cf16f9ea0
bpo-32363: Disable Task.set_exception() and Task.set_result() (#4923) 2017-12-25 10:48:15 -05:00
Yury Selivanov ca9b36cd1a
bpo-32415: Add asyncio.Task.get_loop() and Future.get_loop() (#4992) 2017-12-23 15:04:15 -05:00
Yury Selivanov 36c2c04478
bpo-32355: Optimize asyncio.gather() (#4913) 2017-12-19 07:19:53 -05:00
Andrew Svetlov 5382c05021
bpo-32351: Use fastpath in asyncio.sleep if delay<0 (#4908)
* Use fastpath in asyncio.sleep if delay<0

* Add NEWS entry
2017-12-17 16:41:30 +02:00
Andrew Svetlov 44d1a5912e
bpo-32250: Implement asyncio.current_task() and asyncio.all_tasks() (#4799) 2017-12-16 21:58:38 +02:00
Andrew Svetlov f74ef458ab
bpo-32311: Implement asyncio.create_task() shortcut (#4848)
* Implement functionality
* Add documentation
2017-12-15 07:04:38 +02:00
Yury Selivanov 9edad3c701
bpo-32272: Remove asyncio.async() function. (#4784) 2017-12-11 10:03:48 -05:00
Yury Selivanov 6370f345e1
bpo-32262: Fix codestyle; use f-strings formatting where necessary. (#4775) 2017-12-10 18:36:12 -05:00
Andrew Svetlov 5f841b5538
bpo-32193: Convert asyncio to async/await usage (#4753)
* Convert asyncio/tasks.py to async/await

* Convert asyncio/queues.py to async/await

* Convert asyncio/test_utils.py to async/await

* Convert asyncio/base_subprocess.py to async/await

* Convert asyncio/subprocess.py to async/await

* Convert asyncio/streams.py to async/await

* Fix comments

* Convert asyncio/locks.py to async/await

* Convert asyncio.sleep to async def

* Add a comment

* Add missing news

* Convert stubs from AbstrctEventLoop to async functions

* Convert subprocess_shell/subprocess_exec

* Convert connect_read_pipe/connect_write_pip to async/await syntax

* Convert create_datagram_endpoint

* Convert create_unix_server/create_unix_connection

* Get rid of old style coroutines in unix_events.py

* Convert selector_events.py to async/await

* Convert wait_closed and create_connection

* Drop redundant line

* Convert base_events.py

* Code cleanup

* Drop redundant comments

* Fix indentation

* Add explicit tests for compatibility between old and new coroutines

* Convert windows event loop to use async/await

* Fix double awaiting of async function

* Convert asyncio/locks.py

* Improve docstring

* Convert tests to async/await

* Convert more tests

* Convert more tests

* Convert more tests

* Convert tests

* Improve test
2017-12-09 00:23:48 +02:00
Victor Stinner 3f438a9fa0
asyncio: Remove asyncio/compat.py (#4606)
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 ;-)
2017-11-28 14:43:52 +01:00
Victor K 4d07189788 bpo-31556: asyncio.wait_for can cancel futures faster with timeout <= 0 (#3703) 2017-10-05 12:04:39 -04:00