Commit Graph

962 Commits

Author SHA1 Message Date
Maximilian Hils 70155412f1
bpo-43253: Don't call shutdown() for invalid socket handles (GH-31892) 2022-03-15 16:59:02 +02:00
Andrew Svetlov 22403d3a81
Drop accidentally added whitespaces in asyncio internals (GH-31900) 2022-03-15 15:22:26 +02:00
Andrew Svetlov 9523c0d84f
bpo-46994: Accept explicit contextvars.Context in asyncio create_task() API (GH-31837) 2022-03-14 13:54:13 +02:00
Alex Grönholm 9f04ee569c
bpo-46805: Add low level UDP socket functions to asyncio (GH-31455) 2022-03-13 18:42:29 +02:00
Andrew Svetlov 7e473e94a5
bpo-46995: Deprecate missing asyncio.Task.set_name() for third-party task implementations (GH-31838)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-03-13 18:34:46 +02:00
Andrew Svetlov f537b2a4fb
bpo-46771: Implement asyncio context managers for handling timeouts (GH-31394)
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>
2022-03-10 08:05:20 -08:00
Stefan Zabka da80d6b2f3
bpo-46955: Expose asyncio.base_events.Server as asyncio.Server (GH-31760)
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>
2022-03-08 23:07:33 +02:00
Serhiy Storchaka 6927632492
Remove trailing spaces (GH-31695) 2022-03-05 17:47:00 +02:00
Guido van Rossum 7d611b4cab
bpo-46771: Remove two controversial lines from Task.cancel() (GH-31623)
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.)
2022-02-28 15:15:56 -08:00
Tin Tvrtković edbee56d69
Taskgroup tweaks (GH-31559)
Now uses .cancel()/.uncancel(), for even fewer broken edge cases.
2022-02-26 08:18:48 -08:00
Tin Tvrtković 7fce1063b6
bpo-46771: Implement task cancel requests counter (GH-31513)
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).
2022-02-23 18:17:00 -08:00
Andrew Svetlov cff4d5c5d2
Inherit asyncio proactor datagram transport from asyncio.DatagramTransport (#31512) 2022-02-23 01:39:24 +02:00
Thomas Grainger 8fb94893e4
bpo-46827: pass sock.type to getaddrinfo in sock_connect (GH-31499)
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>
2022-02-22 22:35:57 +02:00
Andrew Svetlov 4140bcb1cd
bpo-45390: Propagate CancelledError's message from cancelled task to its awaiter (GH-31383)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-02-21 22:59:04 +02:00
Serhiy Storchaka 195a46d6ff
bpo-46796: Simplify handling of removed parameter "loop" in asyncio (GH-31431) 2022-02-21 13:25:52 +02:00
Andrew Svetlov 1f9d4c93af
Raise TypeError if SSLSocket is passed to asyncio transport-based methods (GH-31442) 2022-02-20 14:17:15 +02:00
Nikita Sobolev 4ab8167b9c
bpo-46672: fix `NameError` in `asyncio.gather` if type check fails (GH-31187)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2022-02-20 12:24:00 +02:00
Andrew Svetlov e7130c2e8c
bpo-46752: Uniform TaskGroup.__repr__ (GH-31409) 2022-02-20 12:07:00 +02:00
Guido van Rossum d85121660e
bpo-46752: Slight improvements to TaskGroup API (GH-31398)
* 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
2022-02-17 21:30:44 -08:00
Guido van Rossum 602630ac18
bpo-46752: Add TaskGroup; add Task..cancelled(),.uncancel() (GH-31270)
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>
2022-02-15 15:42:04 -08:00
Alex Waygood 1d81fdc4c0
bpo-46741: Update `asyncio.protocols.BufferedProtocol` docstring (31327)
The docstring for `BufferedProtocol` states that the class is still an "experimental API", but it has been considered stable since 3.8.
2022-02-15 18:39:28 +02:00
Kumar Aditya 13c10bfb77
bpo-44011: New asyncio ssl implementation (#31275)
* bpo-44011: New asyncio ssl implementation

Co-Authored-By: Andrew Svetlov <andrew.svetlov@gmail.com>

* fix warning

* fix typo

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2022-02-15 15:04:00 +02:00
Emiya 64568acbd8
bpo-46487: Add `get_write_buffer_limits` to Write and _SSLProtocol transports (GH-30958)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2022-02-01 18:05:02 +02:00
Kumar Aditya 24cc6411ad
bpo-26552: Fixed case where failing `asyncio.ensure_future` did not close the coroutine (#30288) 2022-01-28 14:24:35 -08:00
Kumar Aditya ea5b96842e
bpo-46469: Make asyncio generic classes return GenericAlias (GH-30777)
* bpo-46469: Make asyncio generic classes return GenericAlias

* 📜🤖 Added by blurb_it.

* Update Misc/NEWS.d/next/Library/2022-01-22-05-05-08.bpo-46469.plUab5.rst

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-01-22 13:28:53 +02:00
Nikita Sobolev fc75bfb8be
bpo-46310: simplify `for` loop in `asyncio/windows_events` (GH-30334) 2022-01-11 12:51:34 +02:00
Kumar Aditya b50e5e916a
bpo-46278: fix typo introduced in GH-30427 (GH-30430)
Automerge-Triggered-By: GH:asvetlov
2022-01-06 05:21:24 -08:00
Andrew Svetlov 3e43fac250
Reflect 'context' arg in 'AbstractEventLoop.call_*()' methods (GH-30427) 2022-01-06 14:31:32 +02:00
Nikita Sobolev 5a2a65096c
bpo-46239: improve error message when importing `asyncio.windows_events` (GH-30353) 2022-01-04 10:44:26 +02:00
Nikita Sobolev 1b111338cf
bpo-46238: reuse `_winapi` constants in `asyncio.windows_events` (GH-30352) 2022-01-04 10:42:19 +02:00
Kumar Aditya a23ab7b6d8
bpo-23819: Fix asyncio tests on python optimized mode (GH-30195) 2021-12-26 13:13:14 +02:00
Kumar Aditya da4b214304
bpo-42413: Replace `concurrent.futures.TimeoutError` and `asyncio.TimeoutError` with builtin `TimeoutError` (GH-30197)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2021-12-19 13:22:40 +02:00
Jim Crist-Harif f3c16a5e72
Re-add `reuse_address` parameter to `create_server` (GH-29733)
This parameter was accidentally removed when fixing
https://bugs.python.org/issue45129, this reverts the unnecessary changes
there.

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2021-12-12 11:47:01 +02:00
Kumar Aditya 265918bb1d
bpo-23819: asyncio: Replace AssertionError with TypeError where it makes sense (GH-29894) 2021-12-07 01:40:35 +02:00
Sam Bull 934a826237
bpo-37658: Actually return result in race condition (GH-29202) 2021-11-29 10:12:57 +02:00
Gregory P. Smith 1dfac27dff
Cleanup a couple of comments left on PR 28775 post-merge. (GH-29079) 2021-10-20 09:17:52 -07:00
Joongi Kim 1a7892414e
bpo-45416: Fix use of asyncio.Condition() with explicit Lock objects (GH-28850)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-10-10 19:01:41 +03:00
Christian Clauss 745c9d9dfc
Fix typos in the Lib directory (GH-28775)
Fix typos in the Lib directory as identified by codespell.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2021-10-06 16:13:48 -07:00
Hugo van Kemenade 59ea704df7
bpo-45129 Remove deprecated reuse_address (GH-28207)
Due to significant security concerns, the reuse_address parameter of
asyncio.loop.create_datagram_endpoint, deprecated in Python 3.9, is
now removed. This is because of the behavior of the socket option
SO_REUSEADDR in UDP.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-09-08 18:58:43 +02:00
Jesús Cea 4b4227b907
Trivial typo in docstring 2021-07-31 06:36:10 +02:00
Mariusz Felisiak 11749e2dc2
bpo-44740: Lowercase "internet" and "web" where appropriate. (#27378)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-07-27 00:11:55 +02:00
Illia Volochii ddd5f36971
bpo-43234: Prohibit non-ThreadPoolExecutor in loop.set_default_executor (GH-24540) 2021-07-01 17:46:49 +03:00
Illia Volochii a1092f6249
bpo-43216: Remove @asyncio.coroutine (GH-26369)
Remove the @asyncio.coroutine decorator
enabling legacy generator-based coroutines to be compatible with async/await
code; remove asyncio.coroutines.CoroWrapper used for wrapping
legacy coroutine objects in the debug mode.

The decorator has been deprecated
since Python 3.8 and the removal was initially scheduled for Python 3.10.
2021-07-01 15:13:59 +02:00
Illia Volochii 1d08d85cbe
bpo-43232: Remove previously deprecated methods on TransportSocket (GH-24538) 2021-06-30 09:19:09 +03:00
Ethan Furman f60b07ab6c
bpo-43945: [Enum] reduce scope of new format() behavior (GH-26752)
* [Enum] reduce scope of new format behavior

Instead of treating all Enums the same for format(), only user mixed-in
enums will be affected.  In other words, IntEnum and IntFlag will not be
changing the format() behavior, due to the requirement that they be
drop-in replacements of existing integer constants.

If a user creates their own integer-based enum, then the new behavior
will apply:

    class Grades(int, Enum):
        A = 5
        B = 4
        C = 3
        D = 2
        F = 0

Now:  format(Grades.B)  -> DeprecationWarning and '4'
3.12:                   -> no warning, and 'B'
2021-06-18 13:15:46 -07:00
Binbin 17b16e13bb
Fix typos in multiple files (GH-26689)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2021-06-12 22:47:44 -04:00
Pablo Galindo 7719953b30
bpo-44011: Revert "New asyncio ssl implementation (GH-17975)" (GH-25848)
This reverts commit 5fb06edbbb and all
subsequent dependent commits.
2021-05-03 16:21:59 +01:00
Christian Heimes 37ebdf0a86
bpo-44011: Fix asyncio tests without ssl module (GH-25840)
Signed-off-by: Christian Heimes <christian@python.org>
2021-05-03 09:38:56 +02:00
Andrew Svetlov 5fb06edbbb
bpo-44011: New asyncio ssl implementation (#17975) 2021-05-03 00:34:15 +03:00
Roberto Hueso 55e5c680dd
bpo-43989: Add signal format specifier for unix_events (GH-25769)
Add format specifier for IntEnum references to avoid 3.12 deprecation warning.
2021-05-01 13:34:29 -07:00
Serhiy Storchaka 172c0f2752
bpo-39529: Deprecate creating new event loop in asyncio.get_event_loop() (GH-23554)
asyncio.get_event_loop() emits now a deprecation warning when it creates a new event loop.
In future releases it will became an alias of asyncio.get_running_loop().
2021-04-25 13:40:44 +03:00
Richard Kojedzinszky 17ef4319a3
bpo-41891: ensure asyncio.wait_for waits for task completion (#22461) 2020-12-18 09:26:04 -08:00
Chris Jerdonek 66d3b589c4
bpo-38323: Add guard clauses in MultiLoopChildWatcher. (#22756)
This is a trivial refactor in preparation for a fix for bpo-38323.
2020-12-16 19:50:25 +02:00
Victor Stinner 99d28c5670
bpo-40364: asyncio uses os.waitstatus_to_exitcode() (GH-23798)
test_unix_events.py no longer checks if waitstatus_to_exitcode() mock
has been called or not to make the test more functional, rather than
checking the exact implementation.
2020-12-16 12:11:24 +01:00
Serhiy Storchaka 8a62887dfb
bpo-42582: Remove asyncio._all_tasks_compat(). (GH-23664)
It was used to implement now removed asyncio.Task.all_tasks().
2020-12-06 18:54:33 +02:00
Zackery Spytz 8085f742f4
bpo-34215: Clarify IncompleteReadError message when "expected" is None (GH-21925)
Co-Authored-By: Tyler Bell <mrbell321@gmail.com>
2020-11-28 16:27:28 +02:00
Wansoo Kim 5b0194ed31
bpo-41241: Unnecessary Type casting in 'if condition' (GH-21396)
This is my first issue!
So, if there's anything wrong, please tell me!

Also, thank you always for all the contributors!

Automerge-Triggered-By: GH:asvetlov
2020-11-28 03:37:08 -08:00
Yurii Karabas e4fe303b8c
bpo-42392: Remove loop parameter from asyncio.tasks and asyncio.subprocess (GH-23521) 2020-11-28 10:21:17 +02:00
Alex Grönholm e3ef4d7f65
bpo-41332: Added missing connect_accepted_socket() to AbstractEventLoop (GH-21533)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Kyle Stanley <aeros167@gmail.com>
2020-11-26 12:09:12 +02:00
Yurii Karabas f533cb80cb
bpo-42392: Remove loop parameter from asyncio.streams (GH-23517) 2020-11-26 09:36:37 +02:00
Yurii Karabas b9127dd6ee
bpo-42392: Improve removal of *loop* parameter in asyncio primitives (GH-23499)
* Update code after merge review from 1st1

* Use a sentinel approach for loop parameter
Remove unnecessary _get_running_loop patching

* Use more clear function name (_verify_parameter_is_marker -> _verify_no_loop)

* Add init method to _LoopBoundMixin to check that loop param wasn't used
2020-11-25 06:50:44 -05:00
Yurii Karabas 0ec34cab9d
bpo-42392: Remove loop parameter form asyncio locks and Queue (#23420)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2020-11-24 20:08:54 +02:00
Diogo Dutra 7e5ef0a571
bpo-42140: Improve asyncio.wait function (GH-22938)
# Improve asyncio.wait function

The original code creates the futures set two times.
We can create this set before, avoiding the second creation.

This new behaviour [breaks the aiokafka library](https://github.com/aio-libs/aiokafka/pull/672), because it gives an iterator to that function, so the second iteration become empty.

Automerge-Triggered-By: GH:1st1
2020-11-10 14:12:52 -08:00
Andrew Svetlov 42d873c63a
bpo-42183: Fix a stack overflow error for asyncio Task or Future repr() (GH-23020)
The overflow occurs under some circumstances when a task or future
recursively returns itself.

Co-authored-by: Kyle Stanley <aeros167@gmail.com>
2020-11-10 15:58:31 +02:00
Jakub Stasiak 3d86d090dc
bpo-42230: Improve asyncio documentation regarding accepting sets vs iterables (GH-23073)
People call wait() and as_completed() with various non-set iterables,
a list should be the most common but there are others as well[1].

Considering typeshed also documents wait()[2] and as_completed()[3]
as accepting arbitrary iterables I think it's a good idea to document
the status quo better.

[1] https://github.com/aio-libs/aiokafka/pull/672
[2] 620989bac5/stdlib/3/asyncio/tasks.pyi (L161)
[3] 620989bac5/stdlib/3/asyncio/tasks.pyi (L40)
2020-11-02 12:56:35 +02:00
Victor Stinner 1b0f0e3d7d
bpo-39651: Fix asyncio proactor _write_to_self() (GH-22197)
Fix a race condition in the call_soon_threadsafe() method of
asyncio.ProactorEventLoop: do nothing if the self-pipe socket has
been closed.
2020-09-12 08:50:18 +02:00
Shantanu 0770ad948c
bpo-41696: Fix handling of debug mode in asyncio.run (#22069)
* bpo-41696: Fix handling of debug mode in asyncio.run

This allows PYTHONASYNCIODEBUG or -X dev to enable asyncio debug mode
when using asyncio.run

* 📜🤖 Added by blurb_it.

Co-authored-by: hauntsaninja <>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2020-09-02 21:54:46 -07:00
Ben Darnell ea5a6363c3
bpo-39010: Fix errors logged on proactor loop restart (#22017)
Stopping and restarting a proactor event loop on windows can lead to
spurious errors logged (ConnectionResetError while reading from the
self pipe). This fixes the issue by ensuring that we don't attempt
to start multiple copies of the self-pipe reading loop.
2020-08-31 12:57:52 -07:00
Elvis Pranskevichus a2118a1462
bpo-37658: Fix asyncio.wait_for() to respect waited task status (#21894)
Currently, if `asyncio.wait_for()` itself is cancelled it will always
raise `CancelledError` regardless if the underlying task is still
running.  This is similar to a race with the timeout, which is handled
already.
2020-08-26 09:42:45 -07:00
Elvis Pranskevichus c517fc7121
bpo-32751: Wait for task cancel in asyncio.wait_for() when timeout <= 0 (#21895)
When I was fixing bpo-32751 back in GH-7216 I missed the case when
*timeout* is zero or negative.  This takes care of that.

Props to @aaliddell for noticing the inconsistency.
2020-08-26 09:42:22 -07:00
Cleber Rosa 1afb42cfa8
bpo-41572: Fix grammar in BaseTransport.close docstring (GH-21914)
Fix grammar in BaseTransport.close docstring.

https://bugs.python.org/issue41572

Signed-off-by: Cleber Rosa <crosa@redhat.com>
2020-08-20 18:10:01 +05:30
James Weaver 29f84294d8
bpo-40782: Change asyncio.AbstractEventLoop.run_in_executor to be a method not a coroutine (GH-21852)
asyncio.AbstractEventLoop.run_in_executor should be a method that returns an asyncio Future, not an async method.
This matches the concrete implementations, and the documentation better.
2020-08-17 07:19:46 -07:00
Victor Stinner 602a971a2a
bpo-41467: Fix asyncio recv_into() on Windows (GH-21720)
On Windows, fix asyncio recv_into() return value when the socket/pipe
is closed (BrokenPipeError): return 0 rather than an empty byte
string (b'').
2020-08-04 02:40:10 +02:00
Alex Grönholm 0dd98c2d00
bpo-41317: Remove reader on cancellation in asyncio.loop.sock_accept() (#21595) 2020-07-23 12:45:08 -07:00
Vinay Sharma d42528a3a2
bpo-37703: improve asyncio.gather documentation regarding cancellation (GH-15312)
These changes updates the doc to comprehensively mention the behaviour of gather.cancel()

Automerge-Triggered-By: @asvetlov
2020-07-20 01:42:57 -07:00
Tony Solomonik 568fb0ff4a
bpo-41273: asyncio's proactor read transport's better performance by using recv_into instead of recv (#21442)
* bpo-41273: Proactor transport read loop to use recv_into

By using recv_into instead of recv we do not allocate a new buffer each
time _loop_reading calls recv.

This betters performance for any stream using proactor (basically any
asyncio stream on windows).

* bpo-41273: Double proactor read transport buffer size

By doubling the read buffer size we get better performance.
2020-07-14 12:41:24 -07:00
Rémi Lapeyre 004e64e805
bpo-40967: Remove deprecated asyncio.Task.current_task() and asyncio.Task.all_tasks() (GH-20874) 2020-07-01 20:41:21 -07:00
Kyle Stanley 2b201369b4
Fix asyncio.to_thread() documented return type (GH-20547)
When I wrote the documentation for `asyncio.to_thread()`, I mistakenly assumed that `return await loop.run_in_executor(...)` within an async def function would return a Future. In reality, it returns a coroutine.

This likely won't affect typical usage of `asyncio.to_thread()`, but it's important for the documentation to be correct here. In general, we also tend to avoid returning futures from high-level APIs in asyncio.
2020-05-31 00:07:04 -07:00
Fantix King 210a137396
bpo-30064: Fix asyncio loop.sock_* race condition issue (#20369) 2020-05-27 12:47:30 -07:00
Kyle Stanley 0f56263e62
bpo-32309: Add support for contextvars in asyncio.to_thread() (GH-20278)
Allows contextvars from the main thread to be accessed in the separate thread used in `asyncio.to_thread()`. See the [discussion](https://github.com/python/cpython/pull/20143#discussion_r427808225) in GH-20143 for context.

Automerge-Triggered-By: @aeros
2020-05-20 22:20:43 -07:00
Kunal Bhalla f2947e354c
s/wakup/wakeup (GH-20250)
(as title)

Automerge-Triggered-By: @Mariatta
2020-05-20 10:12:37 -07:00
Kyle Stanley cc2bbc2227
bpo-32309: Implement asyncio.to_thread() (GH-20143)
Implements `asyncio.to_thread`, a coroutine for asynchronously running IO-bound functions in a separate thread without blocking the event loop. See the discussion starting from [here](https://github.com/python/cpython/pull/18410#issuecomment-628930973) in GH-18410 for context.

Automerge-Triggered-By: @aeros
2020-05-18 20:03:28 -07:00
Chris Jerdonek da742ba826
bpo-31033: Improve the traceback for cancelled asyncio tasks (GH-19951)
When an asyncio.Task is cancelled, the exception traceback now
starts with where the task was first interrupted.  Previously,
the traceback only had "depth one."
2020-05-17 22:47:31 -07:00
Chris Jerdonek 1ce5841eca
bpo-31033: Add a msg argument to Future.cancel() and Task.cancel() (GH-19979) 2020-05-15 16:55:50 -07:00
romasku 382a5635bd
bpo-40607: Reraise exception during task cancelation in asyncio.wait_for() (GH-20054)
Currently, if asyncio.wait_for() timeout expires, it cancels
inner future and then always raises TimeoutError. In case
those future is task, it can handle cancelation mannually,
and those process can lead to some other exception. Current
implementation silently loses thoses exception.

To resolve this, wait_for will check was the cancelation
successfull or not. In case there was exception, wait_for
will reraise it.

Co-authored-by: Roman Skurikhin <roman.skurikhin@cruxlab.com>
2020-05-15 13:12:05 -07:00
Victor Stinner 90549676e0
bpo-40443: Remove unused imports in the stdlib (GH-19803) 2020-04-30 11:26:33 +02:00
Galden 02152b7332
Fix typo from Lib/asyncio/events.py (GH-19410) 2020-04-14 09:04:32 +09:00
Lidi Zheng 4482337dec
bpo-39764: Make Task.get_stack accept ag_frame (#18669)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2020-03-02 14:45:54 +02:00
Markus Mohrhard 374d998b50
bpo-39609: set the thread_name_prefix for the default asyncio executor (GH-18458)
Just a small debugging improvement to identify the asyncio executor threads.
2020-02-27 12:01:47 -08:00
Andrew Svetlov 90d9ba6ef1
bpo-34793: Drop old-style context managers in asyncio.locks (GH-17533) 2020-02-01 13:12:52 +02:00
Kyle Stanley 0ca7cc7fc0 bpo-38356: Fix ThreadedChildWatcher thread leak in test_asyncio (GH-16552)
Motivation for this PR (comment from @vstinner in bpo issue):
```
Warning seen o AMD64 Ubuntu Shared 3.x buildbot:
https://buildbot.python.org/all/#/builders/141/builds/2593

test_devnull_output (test.test_a=syncio.test_subprocess.SubprocessThreadedWatcherTests) ...
Warning -- threading_cleanup() failed to cleanup 1 threads (count: 1, dangling: 2)
```
The following implementation details for the new method are TBD:

1) Public vs private

2) Inclusion in `close()`

3) Name

4) Coroutine vs subroutine method

5) *timeout* parameter

If it's a private method, 3, 4, and 5 are significantly less important.

I started with the most minimal implementation that fixes the dangling threads without modifying the regression tests, which I think is particularly important. I typically try to avoid directly modifying existing tests as much as possible unless it's necessary to do so. However, I am open to changing any part of this.


https://bugs.python.org/issue38356
2020-01-12 03:02:50 -08:00
Andrew Svetlov 10ac0cded2 bpo-39191: Fix RuntimeWarning in asyncio test (GH-17863)
https://bugs.python.org/issue39191
2020-01-07 05:23:01 -08:00
Andrew Svetlov 3a5de51159
Fix #39191: Don't spawn a task before failing (#17796) 2020-01-04 11:10:14 +02:00
Kyle Stanley 89aa7f0ede bpo-34790: Implement deprecation of passing coroutines to asyncio.wait() (GH-16977) 2019-12-30 13:50:19 +02:00
Andrew Svetlov 025eeaa196
Fix import path for asyncio.TimeoutError (#17691) 2019-12-24 12:46:42 +02:00
Kyle Stanley ab513a38c9 bpo-37228: Fix loop.create_datagram_endpoint()'s usage of SO_REUSEADDR (#17311) 2019-12-09 15:21:10 +01:00
Victor Stinner 82b4950b5e
bpo-39006: Fix asyncio when the ssl module is missing (GH-17524)
Fix asyncio when the ssl module is missing: only check for
ssl.SSLSocket instance if the ssl module is available.
2019-12-09 15:02:03 +01:00
idomic 892f9e0777 bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions (GH-16457)
https://bugs.python.org/issue37404
2019-12-07 03:52:35 -08:00
Andrew Svetlov 7ddcd0caa4
bpo-38529: Fix asyncio stream warning (GH-17474) 2019-12-07 13:22:00 +02:00
Batuhan Taşkaya dec367261e bpo-38978: Implement __class_getitem__ for asyncio objects (GH-17491)
https://bugs.python.org/issue38978
2019-12-07 03:05:07 -08:00
Victor Stinner e76ee1a72b
bpo-38982: Fix asyncio PidfdChildWatcher on waitpid() error (GH-17477)
If waitpid() is called elsewhere, waitpid() call fails with
ChildProcessError: use return code 255 in this case, and log a
warning. It ensure that the pidfd file descriptor is closed if this
error occurs.
2019-12-06 16:32:41 +01:00
Hill Ma 99eb70a9eb bpo-38951: Use threading.main_thread() check in asyncio (GH-17433)
https://bugs.python.org/issue38951
2019-12-05 04:40:12 -08:00
Pablo Galindo 293dd23477
Remove binding of captured exceptions when not used to reduce the chances of creating cycles (GH-17246)
Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles.

See for example GH-13135
2019-11-19 21:34:03 +00:00
Kyle Stanley 3f8cebd32c bpo-38692: Add asyncio.PidfdChildWatcher to __all__ (GH-17161)
/cc @asvetlov @1st1 


https://bugs.python.org/issue38692



Automerge-Triggered-By: @benjaminp
2019-11-14 18:47:56 -08:00
Benjamin Peterson 3ccdd9b180
closes bpo-38692: Add a pidfd child process watcher to asyncio. (GH-17069) 2019-11-13 19:08:50 -08:00
Andrew Svetlov dad6be5ffe bpo-38785: Prevent asyncio from crashing (GH-17144)
if parent `__init__` is not called from a constructor of object derived from `asyncio.Future`



https://bugs.python.org/issue38785
2019-11-13 13:36:46 -08:00
Victor Stinner 1b53a24fb4
bpo-34679: ProactorEventLoop only uses set_wakeup_fd() in main thread (GH-16901)
bpo-34679, bpo-38563: asyncio.ProactorEventLoop.close() now only calls
signal.set_wakeup_fd() in the main thread.
2019-10-23 17:25:29 +02:00
idomic b23a8423a9 bpo-34344 Fix AbstractEventLoopPolicy.get_event_loop docstring (GH-16463) 2019-10-03 17:08:29 -04:00
Kyle Stanley e407013089 Fix and improve `asyncio.run()` docs (GH-16403) 2019-09-30 17:12:21 -07:00
Yury Selivanov 6758e6e12a
bpo-38242: Revert "bpo-36889: Merge asyncio streams (GH-13251)" (#16482)
See https://bugs.python.org/issue38242 for more details
2019-09-29 21:59:55 -07:00
Andrew Svetlov 58498bc717
bpo-38019: correctly handle pause/resume reading of closed asyncio unix pipe (GH-16472) 2019-09-29 15:00:35 +03:00
Yury Selivanov edad4d89e3 bpo-38248: Fix inconsistent immediate asyncio.Task cancellation (GH-16330) 2019-09-25 03:32:08 -07:00
Emmanuel Arias 17deb16883 bpo-38260: Add Docs on asyncio.run (GH-16337)
Add docs about return and raise exception on asyncio.run





https://bugs.python.org/issue38260



Automerge-Triggered-By: @asvetlov
2019-09-25 01:53:49 -07:00
Kyle Stanley 9fdc64cf12 bpo-34037: Fix test_asyncio failure and add loop.shutdown_default_executor() (GH-15735) 2019-09-19 15:47:22 +03:00
Andrew Svetlov 9eb35ab0d7
bpo-38148: Add slots to asyncio transports (GH-16077)
* bpo-38148: Add slots to asyncio transports

* Update Misc/NEWS.d/next/Library/2019-09-13-08-55-43.bpo-38148.Lnww6D.rst

Co-Authored-By: Kyle Stanley <aeros167@gmail.com>
2019-09-13 15:18:46 +03:00
Xtreak d31b31516c bpo-36889: Document Stream class and add docstrings (GH-14488)
* This just copies the docs from `StreamWriter` and `StreamReader`.
* Add docstring for asyncio functions.


https://bugs.python.org/issue36889



Automerge-Triggered-By: @asvetlov
2019-09-13 03:52:38 -07:00
Andrew Svetlov a488879cba
bpo-36373: Deprecate explicit loop in task and subprocess API (GH-16033) 2019-09-12 15:40:40 +03:00
Andrew Svetlov 7264e92b71 bpo-36373: Fix deprecation warnings (GH-15889)
https://bugs.python.org/issue36373
2019-09-11 01:20:24 -07:00
Andrew Svetlov 12c122ae95 bpo-38066: Hide internal Stream methods (GH-15762)
feed_eof(), feed_data(), set_exception(), and set_transport() are prefixed with underscore now.


https://bugs.python.org/issue38066
2019-09-10 05:56:14 -07:00
Emmanuel Arias 9008be303a bpo-36373: Deprecate explicit loop parameter in all public asyncio APIs [queue] (GH-13950)
This PR deprecate explicit loop parameters in all public asyncio APIs

This issues is split to be easier to review.

fourth step: queue.py





https://bugs.python.org/issue36373
2019-09-10 04:46:12 -07:00
Emmanuel Arias 537877d85d bpo-36373: Deprecate explicit loop parameter in all public asyncio APIs [locks] (GH-13920)
This PR deprecate explicit loop parameters in all public asyncio APIs

This issues is split to be easier to review.

Third step: locks.py





https://bugs.python.org/issue36373
2019-09-10 03:55:07 -07:00
Min ho Kim 39d87b5471 Fix typos mostly in comments, docs and test names (GH-15209) 2019-08-30 16:21:19 -04:00
Andrew Svetlov 1c06009986
bpo-34679: Restore instantiation Windows IOCP event loop from non-main thread (#15492)
* Restore running proactor event loop from non-main thread

Co-Authored-By: Kyle Stanley <aeros167@gmail.com>
2019-08-26 12:51:08 +03:00
Serhiy Storchaka 662db125cd
bpo-37685: Fixed __eq__, __lt__ etc implementations in some classes. (GH-14952)
They now return NotImplemented for unsupported type of the other operand.
2019-08-08 08:42:54 +03:00
Min ho Kim c4cacc8c5e Fix typos in comments, docs and test names (#15018)
* Fix typos in comments, docs and test names

* Update test_pyparse.py

account for change in string length

* Apply suggestion: splitable -> splittable

Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu>

* Apply suggestion: splitable -> splittable

Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu>

* Apply suggestion: Dealloccte -> Deallocate

Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu>

* Update posixmodule checksum.

* Reverse idlelib changes.
2019-07-30 18:16:13 -04:00
Min ho Kim 96e12d5f4f Fix typos in docs, comments and test assert messages (#14872) 2019-07-21 16:12:33 -04:00
Andrew Svetlov 0d671c04c3
bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread (GH-14344) 2019-06-30 12:54:59 +03:00
Andrew Svetlov 97d15b1ee0
Replace deprecation warning with RuntimeError (GH-14397) 2019-06-27 14:38:47 +03:00
Andrew Svetlov 0237265e82
Use threadpool for reading from file in sendfile fallback mode (#14076) 2019-06-15 14:05:35 +03:00
Andrew Svetlov ef2152354f
bpo-37279: Fix asyncio sendfile support when extra data are sent in fallback mode. (GH-14075) 2019-06-15 14:05:08 +03:00
Andrew Svetlov 65aa64fae8 bpo-36607: Eliminate RuntimeError raised by asyncio.all_tasks() (GH-13971)
If internal tasks weak set is changed by another thread during iteration.



https://bugs.python.org/issue36607
2019-06-11 08:27:30 -07:00
Zackery Spytz 9aa78566fb bpo-34767: Do not always create a collections.deque() in asyncio.Lock() (GH-13834)
https://bugs.python.org/issue34767
2019-06-05 02:33:26 -07:00
Emmanuel Arias 6d64a8f49e bpo-36373: Deprecate explicit loop parameter in all public asyncio APIs [streams] (GH-13671)
This PR deprecate explicit loop parameters in all public asyncio APIs

This issues is split to be easier to review.

Second step: streams.py





https://bugs.python.org/issue36373
2019-06-04 22:45:53 -07:00
Łukasz Langa 7f9a2ae780
Revert "bpo-34037, asyncio: add BaseEventLoop.wait_executor_on_close (GH-13786)" (#13802)
This reverts commit 0f0a30f4da.
2019-06-04 13:03:20 +02:00
Andrew Svetlov 9535aff942 Revert "bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread (#13630)" (GH-13793)
https://bugs.python.org/issue35621
2019-06-03 17:09:19 -07:00
Victor Stinner 0f0a30f4da
bpo-34037, asyncio: add BaseEventLoop.wait_executor_on_close (GH-13786)
Add BaseEventLoop.wait_executor_on_close attribute: true by default.

loop.close() now waits for the default executor to finish by default.
Set loop.wait_executor_on_close attribute to False to not wait for
the executor.
2019-06-03 23:31:04 +02:00
Xtreak 0d70227e41 Fix typos in docs and docstrings (GH-13745) 2019-06-03 01:12:33 +02:00
Andrew Svetlov 13ed07998a
bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread (#13630) 2019-06-02 13:56:38 +03:00
Alex Grönholm 98ef92002e bpo-36999: Add asyncio.Task.get_coro() (GH-13680)
https://bugs.python.org/issue36999
2019-05-30 08:30:09 -07:00
依云 744c08a9c7 bpo-35246: fix support for path-like args in asyncio subprocess (GH-13628)
Drop isinstance checks from create_subprocess_exec function and let
subprocess module do them.

https://bugs.python.org/issue35246


https://bugs.python.org/issue35246
2019-05-28 23:50:59 -07:00
Andrew Svetlov bafd4b5ac8 bpo-29883: Asyncio proactor udp (GH-13440)
Follow-up for #1067


https://bugs.python.org/issue29883
2019-05-28 02:52:15 -07:00
sbstp f0d4c64019 bpo-36686: Improve the documentation of the std* params in loop.subprocess_exec (GH-13586)
https://bugs.python.org/issue36686
2019-05-27 16:51:19 -07:00
Andrew Svetlov 23b4b697e5 bpo-36889: Merge asyncio streams (GH-13251)
https://bugs.python.org/issue36889
2019-05-27 12:56:22 -07:00
Yury Selivanov 8cd5165ba0 bpo-37027: Return a proxy socket object from transp.get_extra_info('socket') (GH-13530)
Return a safe to use proxy socket object from `transport.get_extra_info('socket')`




https://bugs.python.org/issue37027
2019-05-27 06:57:19 -07:00
Andrew Svetlov 1f39c28e48 bpo-37035: Don't log OSError (GH-13548)
https://bugs.python.org/issue37035
2019-05-27 06:28:34 -07:00
Yury Selivanov 431b540bf7
bpo-32528: Make asyncio.CancelledError a BaseException. (GH-13528)
This will address the common mistake many asyncio users make:
an "except Exception" clause breaking Tasks cancellation.

In addition to this change, we stop inheriting asyncio.TimeoutError
and asyncio.InvalidStateError from their concurrent.futures.*
counterparts.  There's no point for these exceptions to share the
inheritance chain.

In 3.9 we'll focus on implementing supervisors and cancel scopes,
which should allow better handling of all exceptions, including
SystemExit and KeyboardInterrupt
2019-05-27 14:45:12 +02:00
Yury Selivanov 16cefb0bc7
bpo-37028: asyncio REPL; activated via 'python -m asyncio'. (GH-13472)
This makes it easy to play with asyncio APIs with simply
using async/await in the REPL.
2019-05-27 13:42:29 +02:00
Matthias Bussonnier d0ebf13e50 bpo-36932: use proper deprecation-removed directive (GH-13349)
.. And update some deprecation warnings with version numbers.




https://bugs.python.org/issue36932
2019-05-20 23:20:10 -07:00
Niklas Fiekas 9932fd91e8 bpo-35721: Close socket pair if Popen in _UnixSubprocessTransport fails (GH-11553)
This slightly expands an existing test case `test_popen_error` to trigger a `ResourceWarning` and fixes it.


https://bugs.python.org/issue35721
2019-05-20 05:02:16 -07:00
Erwan Le Pape ac8eb8f36b bpo-35545: Fix asyncio discarding IPv6 scopes (GH-11271)
This PR proposes a solution to [bpo-35545](https://bugs.python.org/issue35545) by adding an optional `flowinfo` and `scopeid` to `asyncio.base_events._ipaddr_info` to carry the full address information into `_ipaddr_info` and avoid discarding IPv6 specific information.

Changelog entry & regression tests to come.


https://bugs.python.org/issue35545
2019-05-17 01:28:39 -07:00