summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
Commit message (Collapse)AuthorAgeFilesLines
* gh-94972: document that shield users need to keep a reference to their task ↵Miss Islington (bot)2022-09-101-2/+9
| | | | | | | | | (GH-96724) Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Guido van Rossum <gvanrossum@gmail.com> (cherry picked from commit 6281affee6423296893b509cd78dc563ca58b196) Co-authored-by: Hendrik Makait <hendrik.makait@gmail.com>
* GH-74116: Allow multiple drain waiters for asyncio.StreamWriter (GH-94705) ↵Miss Islington (bot)2022-08-301-19/+16
| | | | | | | | | (#96395) (cherry picked from commit e5b2453e61ba5376831093236d598ef5f9f1de61) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* gh-90467: StreamReaderProtocol - add strong reference to created task ↵Miss Islington (bot)2022-08-301-1/+3
| | | | | | | | | (GH-96323) (#96344) (cherry picked from commit e860e521ec0d84e175269aeb15cf24bd6053ad17) Co-authored-by: Kirill <iam@python273.pw> Co-authored-by: Kirill <iam@python273.pw>
* GH-95704: Don't suppress errors from tasks when TG is cancelled (GH-95761)Miss Islington (bot)2022-08-171-4/+3
| | | | | | | | | | | | | | | | When a task catches CancelledError and raises some other error, the other error should not silently be suppressed. Any scenario where a task crashes in cleanup upon cancellation will now result in an ExceptionGroup wrapping the crash(es) instead of propagating CancelledError and ignoring the side errors. NOTE: This represents a change in behavior (hence the need to change several tests). But it is only an edge case. Co-authored-by: Thomas Grainger <tagrain@gmail.com> (cherry picked from commit f51f54f39d384da63be622bcdc9cf4cfb43bad3d) Co-authored-by: Guido van Rossum <guido@python.org>
* GH-95899: fix asyncio.Runner to call set_event_loop only once (GH-95900) ↵Miss Islington (bot)2022-08-151-3/+5
| | | | | | | | (#96003) (cherry picked from commit 914f6367a0d015986dafa7a9d542e24192753b6b) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* gh-95724: Clarify taskgroups.py license. (GH-95847)Miss Islington (bot)2022-08-111-1/+2
| | | | | (cherry picked from commit 7da4937748eb588bb0e977839061ce76cab1b252) Co-authored-by: Yury Selivanov <yury@edgedb.com>
* gh-91323: Revert "Allow overriding a future compliance check in asyncio.Task ↵Miss Islington (bot)2022-08-041-5/+1
| | | | | | | | (GH-32197)" (GH-95442) (GH-95652) This reverts commit d4bb38f82bf18b00db3129031ce4969b6f0caab9. (cherry picked from commit 0342c93a6b866118c894c4e1120fb4db316adebb) Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* GH-95289: Always call uncancel() when parent cancellation is requested ↵Miss Islington (bot)2022-08-041-8/+9
| | | | | | | | (GH-95602) Co-authored-by: Guido van Rossum <guido@python.org> (cherry picked from commit 2fef27589e44c91042c2598b5cad6c6ad0516d93) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* GH-95097: fix `asyncio.run` for tasks without `uncancel` method (GH-95211) ↵Miss Islington (bot)2022-07-291-4/+5
| | | | | | | | (GH-95387) (cherry picked from commit 54f48844d18bc6fb98849f15a2fc08f92ad240ea) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Thomas Grainger <tagrain@gmail.com>
* gh-95051: ensure that timeouts scheduled with `asyncio.Timeout` that have ↵Miss Islington (bot)2022-07-261-4/+4
| | | | | | | | already expired are deliverered promptly (GH-95109) (GH-95216) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> (cherry picked from commit 0c6f898005099be189ee65bcfda659f5fc13b802) Co-authored-by: Thomas Grainger <tagrain@gmail.com>
* [3.11] bpo-45924: Fix asyncio incorrect traceback when future's exception is ↵Miss Islington (bot)2022-07-111-1/+2
| | | | | raised multiple times (GH-30274) (#94747) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* GH-93896: AAlways set event loop in asyncio.run and IsolatedAsyncioTestCase ↵Miss Islington (bot)2022-07-061-0/+6
| | | | | | | (GH-94593) (cherry picked from commit 14fea6b4d25658bc00adbb97dd40ea3d3e6843ad) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* GH-94398: TaskGroup: Fail create_task() during shutdown (GH-94400) (GH-94463)Miss Islington (bot)2022-06-301-0/+2
| | | | | | | | | | Once the task group is shutting down, it should not be possible to create a new task. Here "shutting down" means `self._aborting` is set, indicating that at least one task has failed and we have cancelled all others. Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 594c3699492bfb007650538726d953cbed55de04) Co-authored-by: Guido van Rossum <guido@python.org>
* gh-93297: Make asyncio task groups prevent child tasks from being GCed ↵Miss Islington (bot)2022-05-271-13/+6
| | | | | | | | | (GH-93299) (#93305) (cherry picked from commit e6a57678cafe18ca132ee9510252168fcc392a8d) Co-authored-by: Yury Selivanov <yury@edgedb.com> Co-authored-by: Yury Selivanov <yury@edgedb.com>
* gh-92841: Fix asyncio's RuntimeError: Event loop is closed (GH-92842)Miss Islington (bot)2022-05-171-1/+1
| | | | | (cherry picked from commit 33880b4b1c60f54aa9e7fa02698a3c82eafe3dc7) Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
* gh-91880 - fix typo (GH-92069)David Hewitt2022-04-301-1/+1
| | | | | https://github.com/python/cpython/issues/91880#issuecomment-1113914241 - With thanks to @MojoVampire for spotting this. Automerge-Triggered-By: GH:gvanrossum
* Fix missing `f` prefix on f-strings (GH-91910)Alexander Shadchin2022-04-271-1/+1
|
* gh-91880: add try/except around `signal.signal` (#91881)David Hewitt2022-04-251-1/+7
| | | | Fixes gh-91880.
* gh-91487: Optimize asyncio UDP speed (GH-91488)msoxzw2022-04-152-2/+9
| | | | | | | Fix #91487 When transferring a small file, e.g. 256 KiB, the speed of this PR is comparable. However, if a large file, e.g. 65536 KiB, is transferred, asyncio UDP will be over 100 times faster than the original. The speed is presumably significantly faster if a larger file is transferred, e.g. 1048576 KiB. Automerge-Triggered-By: GH:gpshead
* gh-79156: Add start_tls() method to streams API (#91453)Oleg Iarygin2022-04-151-0/+21
| | | | | | | | | | | | | The existing event loop `start_tls()` method is not sufficient for connections using the streams API. The existing StreamReader works because the new transport passes received data to the original protocol. The StreamWriter must then write data to the new transport, and the StreamReaderProtocol must be updated to close the new transport correctly. The new StreamWriter `start_tls()` updates itself and the reader protocol to the new SSL transport. Co-authored-by: Ian Good <icgood@gmail.com>
* bpo-47167: Allow overriding a future compliance check in asyncio.Task (GH-32197)Andrew Svetlov2022-04-011-1/+5
|
* bpo-39622: Interrupt the main asyncio task on Ctrl+C (GH-32105)Andrew Svetlov2022-03-301-1/+36
| | | Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131)Vincent Bernat2022-03-281-1/+2
| | | Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
* bpo-47062: Rename factory argument to loop_factory (GH-32113)Andrew Svetlov2022-03-251-5/+5
|
* bpo-43352: Add a Barrier object in asyncio lib (GH-24903)Duprat2022-03-252-3/+161
| | | | Co-authored-by: Yury Selivanov <yury@edgedb.com> Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
* bpo-47062: Implement asyncio.Runner context manager (GH-31799)Andrew Svetlov2022-03-241-18/+106
| | | Co-authored-by: Zachary Ware <zach@python.org>
* bpo-46829: Deprecate passing a message into Future.cancel() and ↵Andrew Svetlov2022-03-232-0/+11
| | | | | Task.cancel() (GH-31840) 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.
* bpo-45997: Fix asyncio.Semaphore re-acquiring order (GH-31910)Andrew Svetlov2022-03-221-6/+10
| | | Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* bpo-34790: Remove passing coroutine objects to asyncio.wait() (GH-31964)Andrew Svetlov2022-03-171-10/+4
| | | Co-authored-by: Yury Selivanov <yury@edgedb.com>
* bpo-47039: Normalize repr() of asyncio future and task objects (GH-31950)Andrew Svetlov2022-03-174-27/+19
|
* bpo-43253: Don't call shutdown() for invalid socket handles (GH-31892)Maximilian Hils2022-03-151-1/+1
|
* Drop accidentally added whitespaces in asyncio internals (GH-31900)Andrew Svetlov2022-03-151-1/+1
|
* bpo-46994: Accept explicit contextvars.Context in asyncio create_task() API ↵Andrew Svetlov2022-03-144-10/+26
| | | | (GH-31837)
* bpo-46805: Add low level UDP socket functions to asyncio (GH-31455)Alex Grönholm2022-03-134-0/+165
|
* bpo-46995: Deprecate missing asyncio.Task.set_name() for third-party task ↵Andrew Svetlov2022-03-131-1/+4
| | | | | implementations (GH-31838) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* bpo-46771: Implement asyncio context managers for handling timeouts (GH-31394)Andrew Svetlov2022-03-102-0/+153
| | | | | | | | | | Example: async with asyncio.timeout(5): await some_task() Will interrupt the await and raise TimeoutError if some_task() takes longer than 5 seconds. Co-authored-by: Guido van Rossum <guido@python.org>
* bpo-46955: Expose asyncio.base_events.Server as asyncio.Server (GH-31760)Stefan Zabka2022-03-081-1/+1
| | | | | | This change aligns the documentation at https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.Server with the actual implementation Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
* Remove trailing spaces (GH-31695)Serhiy Storchaka2022-03-052-4/+4
|
* bpo-46771: Remove two controversial lines from Task.cancel() (GH-31623)Guido van Rossum2022-02-281-2/+5
| | | | | | | | | | | | | | | Also from the _asyncio C accelerator module, and adjust one test that the change caused to fail. For more discussion see the discussion starting here: https://github.com/python/cpython/pull/31394#issuecomment-1053545331 (Basically, @asvetlov proposed to return False from cancel() when there is already a pending cancellation, and I went along, even though it wasn't necessary for the task group implementation, and @agronholm has come up with a counterexample that fails because of this change. So now I'm changing it back to the old semantics (but still bumping the counter) until we can have a proper discussion about this.)
* Taskgroup tweaks (GH-31559)Tin Tvrtković2022-02-261-27/+23
| | | Now uses .cancel()/.uncancel(), for even fewer broken edge cases.
* bpo-46771: Implement task cancel requests counter (GH-31513)Tin Tvrtković2022-02-241-9/+21
| | | | | This changes cancelling() and uncancel() to return the count of pending cancellations. This can be used to avoid bugs in certain edge cases (e.g. two timeouts going off at the same time).
* Inherit asyncio proactor datagram transport from asyncio.DatagramTransport ↵Andrew Svetlov2022-02-221-1/+2
| | | | (#31512)
* bpo-46827: pass sock.type to getaddrinfo in sock_connect (GH-31499)Thomas Grainger2022-02-221-1/+3
| | | | | Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
* bpo-45390: Propagate CancelledError's message from cancelled task to its ↵Andrew Svetlov2022-02-211-0/+5
| | | | | | awaiter (GH-31383) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-46796: Simplify handling of removed parameter "loop" in asyncio (GH-31431)Serhiy Storchaka2022-02-213-22/+7
|
* Raise TypeError if SSLSocket is passed to asyncio transport-based methods ↵Andrew Svetlov2022-02-202-10/+20
| | | | (GH-31442)
* bpo-46672: fix `NameError` in `asyncio.gather` if type check fails (GH-31187)Nikita Sobolev2022-02-201-1/+2
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* bpo-46752: Uniform TaskGroup.__repr__ (GH-31409)Andrew Svetlov2022-02-201-8/+10
|
* bpo-46752: Slight improvements to TaskGroup API (GH-31398)Guido van Rossum2022-02-181-18/+4
| | | | | | | | | | | | | | | | | * Remove task group names (for now) We're not sure that they are needed, and once in the code we would never be able to get rid of them. Yury wrote: > Ideally, there should be a way for someone to build a "trace" > of taskgroups/task leading to the current running task. > We could do that using contextvars, but I'm not sure we should > do that in 3.11. * Pass optional name on to task in create_task() * Remove a bunch of unused stuff
* bpo-46752: Add TaskGroup; add Task..cancelled(),.uncancel() (GH-31270)Guido van Rossum2022-02-154-2/+252
| | | | | | | | | | | | | | | | | asyncio/taskgroups.py is an adaptation of taskgroup.py from EdgeDb, with the following key changes: - Allow creating new tasks as long as the last task hasn't finished - Raise [Base]ExceptionGroup (directly) rather than TaskGroupError deriving from MultiError - Instead of monkey-patching the parent task's cancel() method, add a new public API to Task The Task class has a new internal flag, `_cancel_requested`, which is set when `.cancel()` is called successfully. The `.cancelling()` method returns the value of this flag. Further `.cancel()` calls while this flag is set return False. To reset this flag, call `.uncancel()`. Thus, a Task that catches and ignores `CancelledError` should call `.uncancel()` if it wants to be cancellable again; until it does so, it is deemed to be busy with uninterruptible cleanup. This new Task API helps solve the problem where TaskGroup needs to distinguish between whether the parent task being cancelled "from the outside" vs. "from inside". Co-authored-by: Yury Selivanov <yury@edgedb.com> Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>