Commit graph

950 commits

Author SHA1 Message Date
Miss Islington (bot)
0681b4c82c
[3.12] gh-111347: Remove wrong assertion in test_sendfile (GH-111377) (#111461)
gh-111347: Remove wrong assertion in test_sendfile (GH-111377)

Windows is different.
(cherry picked from commit fa35b9e89b)

Co-authored-by: zcxsythenew <30565051+zcxsythenew@users.noreply.github.com>
2023-10-29 10:29:29 -07: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)
9aa899354a
[3.12] gh-110695: test_asyncio uses 50 ms for clock resolution (GH-110952) (#110970)
gh-110695: test_asyncio uses 50 ms for clock resolution (GH-110952)

Before utils.CLOCK_RES constant was added (20 ms), test_asyncio
already used 50 ms.
(cherry picked from commit 9a9fba825f)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-17 10:13:31 +00:00
Miss Islington (bot)
c2d542b42c
[3.12] gh-108303: Move all certificates to Lib/test/certdata/ (GH-109489) (#109682)
* gh-108303: Move all certificates to `Lib/test/certdata/` (GH-109489)
(cherry picked from commit e57ecf6bbc)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

Python 3.12 backport: update also `test_nntplib`.

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: T. Wouters <thomas@python.org>
2023-10-10 22:38:18 +02:00
Victor Stinner
e188534607
[3.12] Add support.MS_WINDOWS constant (#110446) (#110452)
Add support.MS_WINDOWS constant (#110446)

(cherry picked from commit e0c4437793)
2023-10-06 01:26:14 +00:00
Miss Islington (bot)
1d87465005
[3.12] gh-110335: asyncio test_unix_events cleans multiprocessing (GH-110336) (#110338)
gh-110335: asyncio test_unix_events cleans multiprocessing (GH-110336)

test_unix_events tests using the multiprocessing module now call
multiprocessing.util._cleanup_tests().
(cherry picked from commit 1337765225)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-04 12:33:14 +02:00
Victor Stinner
0745ab88e5
[3.12] gh-110088, gh-109878: Fix test_asyncio timeouts (#110092) (#110098)
gh-110088, gh-109878: Fix test_asyncio timeouts (#110092)

Fix test_asyncio timeouts: don't measure the maximum duration, a test
should not measure a CI performance. Only measure the minimum
duration when a task has a timeout or delay. Add CLOCK_RES to
test_asyncio.utils.

(cherry picked from commit db0a258e79)
2023-10-02 19:35:29 +00:00
Miss Islington (bot)
ce332aa8c5
[3.12] gh-110088: Fix asyncio test_prompt_cancellation() (GH-110157) (#110158)
gh-110088: Fix asyncio test_prompt_cancellation() (GH-110157)

Don't measure the CI performance: don't test the maximum elapsed
time. The check failed on a slow CI.
(cherry picked from commit c62b49ecc8)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-02 17:47:41 +02:00
Miss Islington (bot)
150bd302bb
[3.12] gh-109833: Fix asyncio test_wait_for() (GH-109834) (#109837)
gh-109833: Fix asyncio test_wait_for() (GH-109834)

Expect the test to be "short" but don't measure the exact performance
of the CI. SHORT_TIMEOUT is about 30 seconds whereas the cancelled
coroutine takes around 1 hour.
(cherry picked from commit f29bc9c9a0)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-02 17:24:51 +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)
05b139b599
[3.12] gh-109582: test_fork_signal_handling should wait for event (GH-109605) (#109695)
gh-109582: test_fork_signal_handling should wait for event (GH-109605)

Sometimes the child_handled event was missing because either
the child quits before it gets a chance to handle the signal,
or the parent asserts before the event notification is
delivered via IPC.  Synchronize explicitly to avoid this.
(cherry picked from commit 608c1f3083)

Co-authored-by: Davide Rizzo <sorcio@gmail.com>
2023-10-02 17:14:30 +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)
8acfb42ea3
[3.12] gh-109295: Clean up multiprocessing in test_asyncio and test_compileall (GH-109298) (#109301)
gh-109295: Clean up multiprocessing in test_asyncio and test_compileall (GH-109298)

test_asyncio and test_compileall now clean up multiprocessing by
calling multiprocessing _cleanup_tests(): explicitly clean up
resources and stop background processes like the resource tracker.
(cherry picked from commit 09ea4b8706)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-09-12 16:22:43 +02:00
Miss Islington (bot)
c9dc2bc0de
[3.12] gh-109015: Add test.support.socket_helper.tcp_blackhole() (GH-109016) (#109041)
gh-109015: Add test.support.socket_helper.tcp_blackhole() (GH-109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).
(cherry picked from commit a52a350977)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-09-08 15:12:29 +02:00
Miss Islington (bot)
639ffd5aa0
[3.12] gh-107895: Fix test_asyncio.test_runners when run it in CPython's "development mode" (GH-108168) (#108196)
gh-107895: Fix test_asyncio.test_runners when run it in CPython's "development mode" (GH-108168)
(cherry picked from commit 014a5b71e7)

Co-authored-by: Joon Hwan 김준환 <xncbf12@gmail.com>
2023-08-21 13:18:04 +02:00
Kumar Aditya
9e6f8d4615
[3.12] gh-105987: Fix reference counting issue in `_asyncio._swap_cur… (#106099)
[3.12] gh-105987: Fix reference counting issue in `_asyncio._swap_current_task` (GH-105989).
(cherry picked from commit d2cbb6e918)

Co-authored-by: chgnrdv <52372310+chgnrdv@users.noreply.github.com>
2023-06-26 08:51:28 +00: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
Itamar Ostricher
85c7bf5bce
gh-103793: Defer formatting task name (#103767)
The default task name is "Task-<counter>" (if no name is passed in during Task creation).
This is initialized in `Task.__init__` (C impl) using string formatting, which can be quite slow.
Actually using the task name in real world code is not very common, so this is wasted init.

Let's defer this string formatting to the first time the name is read (in `get_name` impl),
so we don't need to pay the string formatting cost if the task name is never read.

We don't change the order in which tasks are assigned numbers (if they are) --
the number is set on task creation, as a PyLong instead of a formatted string.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2023-04-29 08:20:09 -07: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
Itamar Ostricher
518050ced1
gh-103780: Use patch instead of mock in asyncio unix events test (#103782) 2023-04-24 20:12:48 +00:00
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
Irit Katriel
482b6eeadc
gh-102799: use sys.exception() instead of sys.exc_info() in tests (#103293) 2023-04-06 11:08:25 +01:00
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
Irit Katriel
b3cc11a08e
gh-102799: remove unnecessary calls to sys.exc_info() in tests (#102800) 2023-03-18 07:19:38 +00:00
Kumar Aditya
4f5774f648
GH-78530: add support for generators in asyncio.wait (#102761) 2023-03-17 06:58:43 +05:30
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
Alex Waygood
401d7a7f00
gh-102515: Remove unused imports in the Lib/ directory (#102516) 2023-03-08 11:45:38 +00:00
Kumar Aditya
a74cd3ba5d
GH-97546: fix flaky asyncio test_wait_for_race_condition test (#102421) 2023-03-05 12:15:22 +05:30
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
Gregory P. Smith
0ca67e6313
GH-84559: Deprecate fork being the multiprocessing default. (#100618)
This starts the process. Users who don't specify their own start method
and use the default on platforms where it is 'fork' will see a
DeprecationWarning upon multiprocessing.Pool() construction or upon
multiprocessing.Process.start() or concurrent.futures.ProcessPool use.

See the related issue and documentation within this change for details.
2023-02-02 15:50:35 -08:00
Shantanu
a178ba82bf
gh-101326: Fix regression when passing None to FutureIter.throw (#101327) 2023-01-25 12:01:01 -08:00
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
6835184a44
GH-100192: fix asyncio subprocess tests to pass env vars to subprocess (#100569) 2022-12-28 11:16:04 +05:30
Kumar Aditya
5369bba8c5
add tests for asyncio transport sockets (#100263) 2022-12-28 10:07:55 +05:30
Kumar Aditya
e97afefda5
GH-100192: add more asyncio subprocess tests (#100194) 2022-12-28 09:42:16 +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
DarioDaF
1bb68ba6d9
gh-99941: Ensure that asyncio.Protocol.data_received receives immutable bytes (#100053) 2022-12-10 15:07:02 -08:00
Fantix King
50b08d5b5f
Fix potential flakiness in test_run_until_complete_baseexception (#100148) 2022-12-10 15:34:22 +05:30
Kumar Aditya
0448deac70
GH-100113: remove remaining yield from usage from asyncio tests (#100114) 2022-12-09 09:22:18 +05:30
Fantix King
e8fff515f0
Fix test_run_until_complete_baseexception test to check for KeyboardInterrupt in asyncio (#24477) 2022-12-08 13:51:04 +05:30
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
Serhiy Storchaka
76f43fc09a
gh-60203: Always pass True/False as boolean arguments in tests (GH-99983)
Unless we explicitly test non-bool values.
2022-12-04 14:28:56 +02:00