Commit Graph

44 Commits

Author SHA1 Message Date
Kristján Valur Jónsson 6b53d5fe04
gh-112202: Ensure that condition.notify() succeeds even when racing with Task.cancel() (#112201)
Also did a general cleanup of asyncio locks.py comments and docstrings.
2024-02-03 08:19:37 -08:00
Kristján Valur Jónsson 52161781a6
GH-111693: Propagate correct asyncio.CancelledError instance out of asyncio.Condition.wait() (#111694)
Also fix a race condition in `asyncio.Semaphore.acquire()` when cancelled.
2024-01-08 11:57:48 -08:00
Cyker Way 68c46ae68b
gh-97545: Make Semaphore run faster. (#97549) 2022-09-26 16:38:00 -07:00
Cyker Way 24e0379624
gh-90155: Fix bug in asyncio.Semaphore and strengthen FIFO guarantee (#93222)
The main problem was that an unluckily timed task cancellation could cause
the semaphore to be stuck. There were also doubts about strict FIFO ordering
of tasks allowed to pass.

The Semaphore implementation was rewritten to be more similar to Lock.
Many tests for edge cases (including cancellation) were added.
2022-09-22 09:34:45 -07:00
Cyker Way 9081bbd036
gh-93247: Fix assert function in asyncio locks test (#93248) 2022-06-05 18:19:18 -07:00
Akuli a4974003ec
gh-93124: Fix typos in comments (GH-93125)
Fixes #93124

Automerge-Triggered-By: GH:rhettinger
2022-05-25 08:34:14 -07:00
Duprat d03acd7270
bpo-43352: Add a Barrier object in asyncio lib (GH-24903)
Co-authored-by: Yury Selivanov <yury@edgedb.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2022-03-26 00:01:21 +02:00
Andrew Svetlov 32e77154dd
bpo-45997: Fix asyncio.Semaphore re-acquiring order (GH-31910)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-03-22 16:02:51 +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 9c06fd8951
bpo-46129: Rewrite asyncio.locks tests with IsolatedAsyncioTestCase (GH-30198)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2021-12-19 16:35:56 +02: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
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
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
Andrew Svetlov 90d9ba6ef1
bpo-34793: Drop old-style context managers in asyncio.locks (GH-17533) 2020-02-01 13:12:52 +02:00
Andrew Svetlov 9aee90018a
bpo-38107: Replace direct future and task contructor calls with factories in asyncio tests (GH-15928) 2019-09-11 16:07:37 +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
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
Andrew Svetlov 68b34a7204 bpo-36921: Deprecate @coroutine for sake of async def (GH-13346)
The second attempt. Now deprecate `@coroutine` only, keep `yield from fut` as is.


https://bugs.python.org/issue36921
2019-05-16 07:52:10 -07:00
Yury Selivanov 9012a0fb4c
bpo-34728: Fix asyncio tests to run under "-Werror" (GH-9661) 2018-10-02 13:53:06 -04:00
Brett Cannon 8425de4147
bpo-33562: Check the global asyncio event loop policy isn't set after any tests (GH-7328) 2018-06-01 20:34:09 -07:00
Elvis Pranskevichus e2b340ab41 bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216)
Currently, asyncio.wait_for(fut), upon reaching the timeout deadline,
cancels the future and returns immediately.  This is problematic for
when *fut* is a Task, because it will be left running for an arbitrary
amount of time.  This behavior is iself surprising and may lead to
related bugs such as the one described in bpo-33638:

    condition = asyncio.Condition()
    async with condition:
        await asyncio.wait_for(condition.wait(), timeout=0.5)

Currently, instead of raising a TimeoutError, the above code will fail
with `RuntimeError: cannot wait on un-acquired lock`, because
`__aexit__` is reached _before_ `condition.wait()` finishes its
cancellation and re-acquires the condition lock.

To resolve this, make `wait_for` await for the task cancellation.
The tradeoff here is that the `timeout` promise may be broken if the
task decides to handle its cancellation in a slow way.  This represents
a behavior change and should probably not be back-patched to 3.6 and
earlier.
2018-05-29 17:31:01 -04:00
Bar Harel 5746510b7a bpo-32841: Fix cancellation in awaiting asyncio.Condition (#5665) 2018-02-14 11:18:11 +02:00
Bar Harel 2f79c01493 bpo-32734: Fix asyncio.Lock multiple acquire safety issue (GH-5466) 2018-02-02 17:04:00 -05:00
Yury Selivanov 3e9751819a
bpo-32273: Move asyncio.test_utils to test.test_asyncio (#4785) 2017-12-11 10:04:40 -05:00
Yury Selivanov 6370f345e1
bpo-32262: Fix codestyle; use f-strings formatting where necessary. (#4775) 2017-12-10 18:36:12 -05:00
Andrew Svetlov 28d8d14013
bpo-32253: Deprecate with statement and bare await for asyncio locks (GH-4764)
* Add test for 'with (yield from lock)'
* Deprecate with statement for asyncio locks
* Document the deprecation
2017-12-09 20:00:05 +02:00
Andrew Svetlov 5f841b5538
bpo-32193: Convert asyncio to async/await usage (#4753)
* Convert asyncio/tasks.py to async/await

* Convert asyncio/queues.py to async/await

* Convert asyncio/test_utils.py to async/await

* Convert asyncio/base_subprocess.py to async/await

* Convert asyncio/subprocess.py to async/await

* Convert asyncio/streams.py to async/await

* Fix comments

* Convert asyncio/locks.py to async/await

* Convert asyncio.sleep to async def

* Add a comment

* Add missing news

* Convert stubs from AbstrctEventLoop to async functions

* Convert subprocess_shell/subprocess_exec

* Convert connect_read_pipe/connect_write_pip to async/await syntax

* Convert create_datagram_endpoint

* Convert create_unix_server/create_unix_connection

* Get rid of old style coroutines in unix_events.py

* Convert selector_events.py to async/await

* Convert wait_closed and create_connection

* Drop redundant line

* Convert base_events.py

* Code cleanup

* Drop redundant comments

* Fix indentation

* Add explicit tests for compatibility between old and new coroutines

* Convert windows event loop to use async/await

* Fix double awaiting of async function

* Convert asyncio/locks.py

* Improve docstring

* Convert tests to async/await

* Convert more tests

* Convert more tests

* Convert more tests

* Convert tests

* Improve test
2017-12-09 00:23:48 +02:00
Mathieu Sornay 894a654a9c Fix waiter cancellation in asyncio.Lock (#1031)
Avoid a deadlock when the waiter who is about to take the lock is
cancelled

Issue #27585
2017-06-09 16:17:40 -04:00
Yury Selivanov 600a349781 Issue #28613: Fix get_event_loop() to return the current loop
when called from coroutines or callbacks.
2016-11-04 14:29:28 -04:00
Martin Panter 0be894b2f6 Issue #27895: Spelling fixes (Contributed by Ville Skyttä). 2016-09-07 12:03:06 +00:00
Yury Selivanov c92bf83a82 Issue #22970: asyncio: Fix inconsistency cancelling Condition.wait.
Patch by David Coles.
2016-06-11 12:00:07 -04:00
Guido van Rossum d455a50773 Also rewrote the guts of asyncio.Semaphore (patch by manipopopo). 2015-09-29 11:54:45 -07:00
Victor Stinner 313a980904 asyncio: sync with Tulip
* _WaitHandleFuture.cancel() now notify IocpProactor through the overlapped
  object that the wait was cancelled.
* Optimize IocpProactor.wait_for_handle() gets the result if the wait is
  signaled immediatly.
* Enhance representation of Future and Future subclasses

  - Add "created at filename:lineno" in the representation
  - Add Future._repr_info() method which can be more easily overriden than
    Future.__repr__(). It should now be more easy to enhance Future
    representation without having to modify each subclass. For example,
    _OverlappedFuture and _WaitHandleFuture get the new "created at" information.
  - Use reprlib to format Future result, and function arguments when formatting a
    callback, to limit the length of the representation.

* Fix repr(_WaitHandleFuture)
* _WaitHandleFuture and _OverlappedFuture: hide frames of internal calls in the
  source traceback.
* Cleanup ProactorIocp._poll(): set the timeout to 0 after the first call to
  GetQueuedCompletionStatus()
* test_locks: close the temporary event loop and check the condition lock
* Remove workaround in test_futures, no more needed
2014-07-29 12:58:23 +02:00
Andrew Svetlov f21fcd09c5 Accept optional lock object in Condition ctor (tulip issue #198) 2014-07-26 17:54:34 +03:00
Victor Stinner 87f16f892c Issue #21163, asyncio: Fix some "Task was destroyed but it is pending!" logs in tests 2014-06-25 23:11:21 +02:00
Victor Stinner c73701de72 asyncio: Refactor tests: add a base TestCase class 2014-06-18 01:36:32 +02:00
Victor Stinner 24ba203504 asyncio: Replace "unittest.mock" with "mock" in unit tests
Use "from unittest import mock". It should simplify my work to merge new tests
in Trollius, because Trollius uses "mock" backport for Python 2.
2014-02-26 10:25:02 +01:00
Guido van Rossum ab3c88983b asyncio: Locks refactor: use a separate context manager; remove Semaphore._locked. 2014-01-25 16:51:57 -08:00
Victor Stinner 8dffc456d7 Update asyncio from the Tulip project
Major changes:

- StreamReader.readexactly() now raises an IncompleteReadError if the
  end of stream is reached before we received enough bytes, instead of
  returning less bytes than requested.

- Unit tests use the main asyncio module instead of submodules like events

- _UnixWritePipeTransport now also supports character devices, as
  _UnixReadPipeTransport. Patch written by Jonathan Slenders.

- Export more symbols: BaseEventLoop, BaseProactorEventLoop,
  BaseSelectorEventLoop, Queue and Queue sublasses, Empty, Full
2014-01-25 15:32:06 +01:00
Guido van Rossum 085869bfee asyncio: Change bounded semaphore into a subclass, like threading.[Bounded]Semaphore. 2013-11-23 15:09:16 -08:00
Guido van Rossum 9c55a58a1d asyncio: Make Semaphore(0) work properly. 2013-11-21 11:07:45 -08:00
Guido van Rossum ccea08462b asyncio: Locks improvements by Arnaud Faure: better repr(), change Conditio\
n structure.
2013-11-04 13:18:19 -08:00
Guido van Rossum 27b7c7ebf1 Initial checkin of asyncio package (== Tulip, == PEP 3156). 2013-10-17 13:40:50 -07:00