Commit Graph

983 Commits

Author SHA1 Message Date
DPR 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>
2023-11-15 01:17:51 +00:00
Pierre Ossman (ThinLinc team) 74b868f636
gh-111246: Remove listening Unix socket on close (#111483)
Try to clean up the socket file we create so we don't add unused noise to the file system.
2023-11-08 08:10:10 -08:00
Kumar Aditya 229f44d353
GH-110894: Call loop exception handler for exceptions in client_connected_cb (#111601)
Call loop exception handler for exceptions in `client_connected_cb` of `asyncio.start_server` so that applications can handle it.
2023-11-02 07:38:18 +00:00
Guido van Rossum 2655369559
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

---------

Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2023-10-28 18:04:29 +00:00
Guido van Rossum c3bb10c930
gh-110205: Fix asyncio ThreadedChildWatcher._join_threads() (#110884)
- `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`.
2023-10-27 15:44:12 -07:00
Serhiy Storchaka 6c23635f2b
gh-111085: Fix invalid state handling in TaskGroup and Timeout (#111111)
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).

Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-10-21 22:18:34 +03:00
Bar Harel 7025844f4c
gh-110961: Fixed asyncio.wait docstring to remove deprecated coroutine reference (#111017)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2023-10-18 04:40:26 +00:00
Thomas Grainger 596589104f
remove redundant call to attach_loop in watcher (#110847) 2023-10-14 10:24:02 +02:00
Russell Keith-Magee a7e2a10a85
gh-110771: Decompose run_forever() into parts (#110773)
Effectively introduce an unstable, private (really: protected) API for subclasses that want to override `run_forever()`.
2023-10-13 14:12:32 +00:00
Thomas Grainger 8c6c14b91b
gh-94597: Add asyncio.EventLoop (#110723)
This is needed to pave the way for deprecating and eventually killing the event loop policy system (which is over-engineered and rarely used).
2023-10-12 07:13:57 -07:00
J. Nick Koston 3ac8e6955f
gh-110733: Micro-optimization in BaseEventLoop._run_once (#110735) 2023-10-11 20:59:27 +00:00
Kristján Valur Jónsson 45cf5b0c69
gh-109955 : Update state transition comments for asyncio.Task (#109910)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2023-09-27 15:24:10 -07:00
Tom Gillespie e721f7a951
Remove loop from docstring for asyncio.streams.open_connection (#108528) 2023-09-26 20:34:15 -07:00
Alex Waygood 19601efa36
gh-109653: Remove unused imports in the `Lib/` directory (#109803) 2023-09-24 15:07:23 +01:00
Victor Stinner cbbdf2c144
gh-109709: Fix asyncio test_stdin_broken_pipe() (#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().
2023-09-22 15:29:42 +02:00
Victor Stinner ced6924630
gh-108973: Fix asyncio test_subprocess_consistent_callbacks() (#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.

Co-authored-by: Davide Rizzo <sorcio@gmail.com>
2023-09-20 15:54:19 +02:00
Nikita Sobolev ad1d6a1c20
gh-108903: Remove unneeded `lambda`s from `asyncio` (GH-108904) 2023-09-05 18:11:12 +03:00
Kumar Aditya b1e5d2c601
Fix patchcheck for `asyncio.tasks` (#108159) 2023-08-20 09:00:42 +00:00
Kumar Aditya 41178e4199
GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (#107650) 2023-08-05 17:48:15 +05:30
J. Nick Koston 9eeb4b485f
gh-82500: Fix asyncio sendfile overflow on 32bit (#107056) 2023-07-22 21:07:14 -07:00
J. Nick Koston b7dc795dfd
gh-106527: asyncio: optimize to add/remove readers and writers (#106528) 2023-07-22 21:07:40 +00:00
Chris Brett 4b4a5b70aa
gh-106634: Corrected minor asyncio doc issues (#106671) 2023-07-13 13:21:13 +05:30
Andrew Geng 3e5ce7968f
gh-106503: asyncio._SelectorSocketTransport: fix cyclic reference on close(). (#106504) 2023-07-07 17:11:54 +05:30
James Webber a12e8ffb49
gh-106075: add `asyncio.taskgroups.__all__` to `asyncio.__all__` (#106090)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-06-26 07:54:03 +00:00
Kumar Aditya 840d02f3f0
GH-105684: Require `asyncio.Task` implementations to support `set_name` method (#105685) 2023-06-13 06:06:40 +00:00
Jay f0fb782ddb
gh-105331: Change `asyncio.sleep` to raise ``ValueError` for nan (#105641)
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-06-12 20:29:02 +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