Commit graph

992 commits

Author SHA1 Message Date
Thomas Grainger
32d457941e
[3.12] gh-124958: fix asyncio.TaskGroup and _PyFuture refcycles (#124959) (#125466)
gh-124958: fix asyncio.TaskGroup and _PyFuture refcycles (#124959)
2024-10-16 21:45:59 -07:00
Miss Islington (bot)
affffc7dda
[3.12] gh-124309: fix staggered race on eager tasks (GH-124847) (#125340)
gh-124309: fix staggered race on eager tasks (GH-124847)

This patch is entirely by Thomas and Peter

(cherry picked from commit 979c0df7c0)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-10-11 20:12:11 -07:00
Miss Islington (bot)
3b5bc8d228
[3.12] gh-124309: Revert eager task factory fix to prevent breaking downstream (GH-124810) (#124817)
gh-124309: Revert eager task factory fix to prevent breaking downstream (GH-124810)

* Revert "GH-124639: add back loop param to staggered_race (GH-124700)"

This reverts commit e0a41a5dd1.

* Revert "gh-124309: Modernize the `staggered_race` implementation to support eager task factories (GH-124390)"

This reverts commit de929f353c.
(cherry picked from commit 133e929a79)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-10-01 01:55:03 +00:00
Miss Islington (bot)
65103adadd
[3.12] GH-124639: add back loop param to staggered_race (GH-124700) (#124744)
GH-124639: add back loop param to staggered_race (GH-124700)
(cherry picked from commit e0a41a5dd1)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-09-29 09:10:41 +05:30
Kumar Aditya
2b54a4ebf1
[3.12] gh-124309: Modernize the staggered_race implementation to support e… (#124574)
gh-124309: Modernize the `staggered_race` implementation to support eager task factories (#124390)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
(cherry picked from commit de929f353c)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-09-26 05:39:46 +00:00
Miss Islington (bot)
41090b7ba0
[3.12] gh-112182: Replace StopIteration with RuntimeError for future (GH-113220) (GH-123033)
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__`
(cherry picked from commit 4826d52338)

Co-authored-by: Jamie Phan <jamie@ordinarylab.dev>
2024-08-15 15:34:53 +00:00
Miss Islington (bot)
0300e33b22
[3.12] gh-121913: Use str(exc) instead of exc.strerror in asyncio.base_events (GH-122269) (#122279)
gh-121913: Use str(exc) instead of exc.strerror in `asyncio.base_events` (GH-122269)
(cherry picked from commit 070f1e2e5b)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2024-07-25 12:15:22 +00:00
Łukasz Langa
c1e834dd78
[3.12] gh-121957: Emit audit events for python -i and python -m asyncio (GH-122117) 2024-07-22 13:41:23 +02:00
Łukasz Langa
0480fd628a
[3.12] Use Cirrus M1 macOS runners for CI (GH-119979) (GH-119987)
(cherry picked from commit 6acb32fac3)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Ee Durbin <ee@python.org>
2024-06-03 18:15:54 +02:00
Miss Islington (bot)
55f65156cb
[3.12] gh-113892: Add a extra check to ProactorEventLoop.sock_connect to ensure that the given socket is in non-blocking mode (GH-119519) (#119913)
(cherry picked from commit cf3bba3f06)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-06-01 16:29:34 +00:00
Miss Islington (bot)
bd2c60f8c2
[3.12] gh-91227: Ignore ERROR_PORT_UNREACHABLE in proactor recvfrom() (GH-32011) (GH-117209)
(cherry picked from commit f11d0d8be8)

Co-authored-by: Erik Soma <stillusingirc@gmail.com>
2024-03-25 12:21:31 +02:00
jkriegshauser
d69c51520e
[3.12] gh-116773: Fix overlapped memory corruption crash (GH-116774) (#117078)
Manual backport of gh-116774.
2024-03-20 13:10:15 -07:00
Terry Jan Reedy
84b023d243
[3.12] chore: fix typos (#116345) (#116370)
Co-authored-by: cui fliter <imcusg@gmail.com>
(cherry picked from commit e7ba6e9dbe)
2024-03-05 18:51:17 +00:00
Miss Islington (bot)
e25ac3ba1d
[3.12] gh-111358: Fix timeout behaviour in BaseEventLoop.shutdown_default_executor (GH-115622) (#115641)
(cherry picked from commit 53d5e67804)

Co-authored-by: Jamie Phan <jamie@ordinarylab.dev>
2024-02-19 00:17:40 +00:00
Travis Howse
49fbb068d5
[3.12] gh-114887 Reject only sockets of type SOCK_STREAM in create_da… (#114980)
Also improve exception message.

(cherry picked from commit 94ec2b9c9c)

Co-authored-by: Donghee Na <donghee.na92@gmail.com>
2024-02-04 15:42:06 -08:00
Miss Islington (bot)
0ee6fbaab6
[3.12] gh-109534: fix reference leak when SSL handshake fails (GH-114074) (#114829)
gh-109534: fix reference leak when SSL handshake fails (GH-114074)
(cherry picked from commit 80aa7b3688)

Co-authored-by: Jamie Phan <jamie@ordinarylab.dev>
2024-02-01 01:00:09 +00:00
Miss Islington (bot)
4bbb9f6f29
[3.12] gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() (GH-114420) (GH-114441)
(cherry picked from commit a53e56e7d8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
2024-01-22 17:15:08 +00:00
Alois Klink
fa7d8e97c2
[3.12] gh-95649: Document that asyncio contains uvloop code (GH-107536) (#114046)
Some of the asyncio SSL changes in GH-31275 [1] were taken from
v0.16.0 of the uvloop project [2]. In order to comply with the MIT
license, we need to just need to document the copyright information.

[1]: https://github.com/python/cpython/pull/31275
[2]: https://github.com/MagicStack/uvloop/tree/v0.16.0

(cherry picked from commit dce30c9cbc)
2024-01-14 02:15:06 +00:00
Miss Islington (bot)
92ba4e10fa
[3.12] gh-113538: Don't error in stream reader protocol callback when task is cancelled (GH-113690) (#113713)
(cherry picked from commit 4681a5271a)

Co-authored-by: Guido van Rossum <guido@python.org>
2024-01-04 20:51:53 +00:00
Miss Islington (bot)
192711856b
[3.12] GH-113214: Fix SSLProto exception handling in SSL-over-SSL scenarios (GH-113334) (#113339)
When wrapped, `_SSLProtocolTransport._force_close(exc)` is called just like in the unwrapped scenario `_SelectorTransport._force_close(exc)` or `_ProactorBasePipeTransport._force_close(exc)` would be called, except here the exception needs to be passed through the `SSLProtocol._abort()` method, which didn't accept an exception object.

This commit ensures that this path works, in the same way that the uvloop implementation of SSLProto passes on the exception (on which the current implementation of SSLProto is based).

(cherry picked from commit 1ff0238594)

Co-authored-by: Martijn Pieters <mj@zopatista.com>
2023-12-20 16:51:36 -08:00
DPR
2ef3676a5b
[3.12] gh-109538: Catch closed loop runtime error and issue warning (GH-111983) (#112142)
* [3.12] gh-109538: Avoid RuntimeError when StreamWriter is deleted with closed loop (GH-111983)

Issue a ResourceWarning instead.

(cherry picked from commit e0f5127975)
gh-109538: Avoid RuntimeError when StreamWriter is deleted with closed loop (#111983)

Issue a ResourceWarning instead.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
(cherry picked from commit e0f5127975)

* Fix missing warnings import
2023-11-16 09:40:55 -08:00
Kumar Aditya
9aa88290d8
[3.12] GH-110894: Call loop exception handler for exceptions in client_connected_cb (GH-111601) (#111632)
Call loop exception handler for exceptions in `client_connected_cb` of `asyncio.start_server` so that applications can handle it..
(cherry picked from commit 229f44d353)
2023-11-02 08:18:49 +00:00
Miss Islington (bot)
2e5d4e24eb
[3.12] gh-79033: Try to fix asyncio.Server.wait_closed() again (GH-111336) (#111424)
gh-79033: Try to fix asyncio.Server.wait_closed() again (GH-111336)

* Try to fix asyncio.Server.wait_closed() again

I identified the condition that `wait_closed()` is intended
to wait for: the server is closed *and* there are no more
active connections.

When this condition first becomes true, `_wakeup()` is called
(either from `close()` or from `_detach()`) and it sets `_waiters`
to `None`. So we just check for `self._waiters is None`; if it's
not `None`, we know we have to wait, and do so.

A problem was that the new test introduced in 3.12 explicitly
tested that `wait_closed()` returns immediately when the server
is *not* closed but there are currently no active connections.
This was a mistake (probably a misunderstanding of the intended
semantics). I've fixed the test, and added a separate test that
checks exactly for this scenario.

I also fixed an oddity where in `_wakeup()` the result of the
waiter was set to the waiter itself. This result is not used
anywhere and I changed this to `None`, to avoid a GC cycle.

* Update Lib/asyncio/base_events.py

---------

(cherry picked from commit 2655369559)

Co-authored-by: Guido van Rossum <guido@python.org>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2023-10-28 18:42:53 +00:00
Miss Islington (bot)
2398036eea
[3.12] gh-110205: Fix asyncio ThreadedChildWatcher._join_threads() (GH-110884) (#111412)
- `ThreadedChildWatcher.close()` is now *officially* a no-op; `_join_threads()` never did anything.
- Threads created by that class are now named `asyncio-waitpid-NNN`.
- `test.test_asyncio.utils.TestCase.close_loop()` now waits for the child watcher's threads, but not forever; if a thread hangs, it raises `RuntimeError`.
(cherry picked from commit c3bb10c930)

Co-authored-by: Guido van Rossum <guido@python.org>
2023-10-27 16:36:05 -07:00
Miss Islington (bot)
028f47754c
[3.12] gh-111085: Fix invalid state handling in TaskGroup and Timeout (GH-111111) (GH-111171)
asyncio.TaskGroup and asyncio.Timeout classes now raise proper RuntimeError
if they are improperly used.

* When they are used without entering the context manager.
* When they are used after finishing.
* When the context manager is entered more than once (simultaneously or
  sequentially).
* If there is no current task when entering the context manager.

They now remain in a consistent state after an exception is thrown,
so subsequent operations can be performed correctly (if they are allowed).

(cherry picked from commit 6c23635f2b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-10-21 19:48:53 +00:00
Miss Islington (bot)
0c56c05022
[3.12] remove redundant call to attach_loop in watcher (GH-110847) (#110867)
(cherry picked from commit 596589104f)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
2023-10-14 12:27:08 +02:00
Miss Islington (bot)
dd67e59bb1
[3.12] gh-109955 : Update state transition comments for asyncio.Task (GH-109910) (#109992)
gh-109955 : Update state transition comments for asyncio.Task (GH-109910)
(cherry picked from commit 45cf5b0c69)

Co-authored-by: Kristján Valur Jónsson <sweskman@gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2023-10-02 17:41:12 +02:00
Miss Islington (bot)
3ab9fdaedb
[3.12] Remove loop from docstring for asyncio.streams.open_connection (GH-108528) (#109941)
Remove loop from docstring for asyncio.streams.open_connection (GH-108528)
(cherry picked from commit e721f7a951)

Co-authored-by: Tom Gillespie <tgbugs@gmail.com>
2023-10-02 17:39:34 +02:00
Miss Islington (bot)
c7cbd82e62
[3.12] gh-109709: Fix asyncio test_stdin_broken_pipe() (GH-109710) (#109731)
gh-109709: Fix asyncio test_stdin_broken_pipe() (GH-109710)

Replace harcoded sleep of 500 ms with synchronization using a pipe.

Fix also Process._feed_stdin(): catch also BrokenPipeError on
stdin.write(input), not only on stdin.drain().
(cherry picked from commit cbbdf2c144)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-02 17:21:51 +02:00
Miss Islington (bot)
5ba9d2b98f
[3.12] gh-108973: Fix asyncio test_subprocess_consistent_callbacks() (GH-109431) (#109609)
gh-108973: Fix asyncio test_subprocess_consistent_callbacks() (GH-109431)

SubprocessProtocol process_exited() method can be called before
pipe_data_received() and pipe_connection_lost() methods. Document it
and adapt the test for that.

Revert commit 282edd7b2a.
_child_watcher_callback() calls immediately _process_exited(): don't
add an additional delay with call_soon(). The reverted change didn't
make _process_exited() more determistic: it can still be called
before pipe_connection_lost() for example.

(cherry picked from commit ced6924630)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Davide Rizzo <sorcio@gmail.com>
2023-10-02 17:03:51 +02:00
Miss Islington (bot)
1e46f1a9a4
[3.12] Fix patchcheck for asyncio.tasks (GH-108159) (#108160)
Fix patchcheck for `asyncio.tasks` (GH-108159)
(cherry picked from commit b1e5d2c601)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2023-08-20 15:49:03 +02:00
Miss Islington (bot)
7853c76906
[3.12] GH-106684: Close asyncio.StreamWriter when asyncio.StreamWriter is not closed by application (GH-107650) (#107656)
GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (GH-107650)
(cherry picked from commit 41178e4199)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-08-10 11:24:22 +02:00
Miss Islington (bot)
dfdded6beb
[3.12] gh-106634: Corrected minor asyncio doc issues (GH-106671) (#106712)
gh-106634: Corrected minor asyncio doc issues (GH-106671)
(cherry picked from commit 4b4a5b70aa)

Co-authored-by: Chris Brett <chrisbrett665@gmail.com>
2023-07-14 15:10:32 +05:30
Miss Islington (bot)
7e883d76c0
[3.12] gh-106503: asyncio._SelectorSocketTransport: fix cyclic reference on close(). (GH-106504) (#106514)
gh-106503: asyncio._SelectorSocketTransport: fix cyclic reference on close(). (GH-106504)
(cherry picked from commit 3e5ce7968f)

Co-authored-by: Andrew Geng <pteromys@gmail.com>
2023-07-07 12:08:22 +00:00
Miss Islington (bot)
8d5d60f72d
[3.12] gh-106075: add asyncio.taskgroups.__all__ to asyncio.__all__ (GH-106090) (#106098)
gh-106075: add `asyncio.taskgroups.__all__` to `asyncio.__all__` (GH-106090)
(cherry picked from commit a12e8ffb49)

Co-authored-by: James Webber <jamestwebber@users.noreply.github.com>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-06-26 12:26:15 +00:00
Guido van Rossum
7fc8e2d462
gh-104340: Suppress warning about unawaited exception for closed pipe stdin (#104586) 2023-05-17 16:45:11 -07:00
Sam Bull
fb8739f0b6
gh-98539: Make _SSLTransportProtocol.abort() safe to call when closed (#104474) 2023-05-14 11:58:13 -07:00
Jacob Bower
bf89d4283a
gh-97696 Remove unnecessary check for eager_start kwarg (#104188)
Instead, add docstring to create_eager_task_factory.
2023-05-09 00:51:58 +00:00
Itamar Ostricher
263abd333d
gh-104144: Optimize gather to finish eagerly when all futures complete eagerly (#104138) 2023-05-06 15:15:27 +00:00
Itamar Ostricher
52d8f36e8c
gh-104144: Skip scheduling a done callback if a TaskGroup task completes eagerly (#104140)
Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-05-05 16:44:03 -07:00
Itamar Ostricher
a474e04388
gh-97696: asyncio eager tasks factory (#102853)
Co-authored-by: Jacob Bower <jbower@meta.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2023-05-01 15:10:13 -06:00
Marek Marczykowski-Górecki
67d140dba7
gh-83925: Make asyncio.subprocess communicate similar to non-asyncio (#18650)
subprocess's communicate(None) closes stdin of the child process, after
sending no (extra) data. Make asyncio variant do the same.
This fixes issues with processes that waits for EOF on stdin before
continuing.
2023-04-27 17:30:26 -07:00
Itayazolay
78942ecd9b
gh-103607: Fix pause_reading to work when called from connection_made in asyncio. (#17425)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-04-27 15:33:29 +05:30
Ali-Akber Saifee
19d2639d1e
gh-103462: Ensure SelectorSocketTransport.writelines registers a writer when data is still pending (#103463) 2023-04-13 10:16:52 +05:30
Kristján Valur Jónsson
04adf2df39
gh-102780: Fix uncancel() call in asyncio timeouts (#102815)
Also use `raise TimeOut from <CancelledError instance>` so that the CancelledError is set
in the `__cause__` field rather than in the `__context__` field.

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-22 10:52:10 -07:00
JosephSBoyle
699cb20ae6
gh-102810: Add docstrings to the public-facing methods of asyncio.Timeout (#102811)
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-19 20:06:09 +00:00
Kumar Aditya
adaed17341
GH-102748: remove legacy support for generator based coroutines from asyncio.iscoroutine (#102749)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-16 20:28:10 +05:30
Kumar Aditya
a44553ea9f
GH-100112: avoid using iterable coroutines in asyncio internally (#100128) 2023-03-16 09:20:43 +05:30
JosephSBoyle
e94edab727
gh-102560 Add docstrings to asyncio.TaskGroup (#102565) 2023-03-14 17:33:19 -07:00
Kumar Aditya
d8485d6c8b
Remove redundant _ensure_future in favor of ensure_future in asyncio (#102398) 2023-03-07 08:44:55 +05:30