Commit graph

972 commits

Author SHA1 Message Date
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
Jan Gosmann
77d95c8373
gh-100226: Clarify StreamReader.read behavior (#101807) 2023-02-17 13:01:26 -08:00
Kumar Aditya
a5024a261a
GH-96764: rewrite asyncio.wait_for to use asyncio.timeout (#98518)
Changes `asyncio.wait_for` to use `asyncio.timeout` as its underlying implementation.
2023-02-17 00:18:21 +05:30
beavailable
cc407b9de6
gh-101317: Add ssl_shutdown_timeout parameter for asyncio.StreamWriter.start_tls (#101335)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-02-01 16:33:59 +05:30
J. Nick Koston
9e947675ae
gh-101143: Remove references to TimerHandle from asyncio.base_events.BaseEventLoop._add_callback (#101197)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-01-21 14:46:07 +05:30
Guido van Rossum
1bc7a73683
GH-100573: Fix server hang caused by os.stat() on named pipe (Windows) (#100959) 2023-01-13 13:24:57 -08:00
Serhiy Storchaka
e5bd5ad70d
gh-100160: Restore and deprecate implicit creation of an event loop (GH-100410)
Partially revert changes made in GH-93453.

asyncio.DefaultEventLoopPolicy.get_event_loop() now emits a
DeprecationWarning and creates and sets a new event loop instead of
raising a RuntimeError if there is no current event loop set.

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
2023-01-13 14:40:29 +02:00
Kumar Aditya
ba8dcdbcab
GH-86508: skip binding to local addresses of different family in asyncio.open_connection (#100615) 2023-01-04 13:30:26 +05:30
Kumar Aditya
c122390a55
GH-91166: Implement zero copy writes for SelectorSocketTransport in asyncio (#31871)
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
2022-12-24 11:21:11 +05:30
Itamar Ostricher
4cc63e0d4e
gh-100344: Add C implementation for asyncio.current_task (#100345)
Co-authored-by: pranavtbhat
2022-12-22 19:08:12 +05:30
Kumar Aditya
a7715ccfba
GH-100133: fix asyncio subprocess losing stderr and stdout output (#100154) 2022-12-21 15:20:26 +05:30
Kumar Aditya
4994f2488f
GH-100363: Speed up asyncio.get_running_loop (#100364) 2022-12-21 15:19:44 +05:30
Richard Kojedzinszky
a6331b605e
gh-100348: Fix ref cycle in asyncio._SelectorSocketTransport with _read_ready_cb (#100349) 2022-12-20 16:10:56 +05:30
DarioDaF
1bb68ba6d9
gh-99941: Ensure that asyncio.Protocol.data_received receives immutable bytes (#100053) 2022-12-10 15:07:02 -08:00
Serhiy Storchaka
fd38a2f0ec
gh-93453: No longer create an event loop in get_event_loop() (#98440)
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>
2022-12-06 18:42:12 +01:00
Kumar Aditya
191708c56c
GH-66285: fix forking in asyncio (#99769)
Closes #66285
2022-11-27 11:24:48 +05:30
Kumar Aditya
351842b46a
GH-66285: Revert "fix forking in asyncio" (#99756) 2022-11-24 23:04:21 +05:30
Guido van Rossum
5d09d11aa0
GH-79033: Fix asyncio.Server.wait_closed() (#98582)
It was a no-op when used as recommended (after close()).

I had to debug one test (test__sock_sendfile_native_failure) --
the cleanup sequence for the test fixture was botched.

Hopefully that's not a portend of problems in user code --
this has never worked so people may well be doing this wrong. :-(

Co-authored-by: kumar aditya
2022-11-24 08:32:58 -07:00
Kumar Aditya
0c1fbc17b4
GH-66285: fix forking in asyncio (#99539)
`asyncio` now does not shares event loop and signal wakeupfd in forked processes.
2022-11-24 09:10:27 +05:30
Dong Uk, Kang
995f6170c7
gh-88863: Clear ref cycles to resolve leak when asyncio.open_connection raises (#95739)
Break reference cycles to resolve memory leak, by
removing local exception and future instances from the frame
2022-11-22 07:06:20 -08:00
Kumar Aditya
f63002755d
GH-99388: add loop_factory parameter to asyncio.run (#99462) 2022-11-14 10:18:51 -08:00