Skip to content

Commit f9579d4

Browse files
authored
Merge branch 'master' into receive_nowait
2 parents a71ab2a + 1dabfd8 commit f9579d4

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

docs/versionhistory.rst

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
4141
- Fixed ``start_blocking_portal()`` raising an unwarranted
4242
``RuntimeError: This portal is not running`` if a task raises an exception that causes
4343
the event loop to be closed
44+
- Fixed ``current_effective_deadline()`` not returning ``-inf`` on asyncio when the
45+
currently active cancel scope has been cancelled (PR by Ganden Schaffner)
4446

4547
**3.6.1**
4648

src/anyio/_backends/_asyncio.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,10 @@ def current_effective_deadline(cls) -> float:
18861886
deadline = math.inf
18871887
while cancel_scope:
18881888
deadline = min(deadline, cancel_scope.deadline)
1889-
if cancel_scope.shield:
1889+
if cancel_scope._cancel_called:
1890+
deadline = -math.inf
1891+
break
1892+
elif cancel_scope.shield:
18901893
break
18911894
else:
18921895
cancel_scope = cancel_scope._parent_scope

src/anyio/_core/_sockets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ async def connect_tcp(
136136
"""
137137
Connect to a host using the TCP protocol.
138138
139-
This function implements the stateless version of the Happy Eyeballs algorithm
140-
(RFC 6555). If ``address`` is a host name that resolves to multiple IP addresses,
139+
This function implements the stateless version of the Happy Eyeballs algorithm (RFC
140+
6555). If ``remote_host`` is a host name that resolves to multiple IP addresses,
141141
each one is tried until one connection attempt succeeds. If the first attempt does
142142
not connected within 250 milliseconds, a second attempt is started using the next
143143
address in the list, and so on. On IPv6 enabled systems, an IPv6 address (if

src/anyio/_core/_tasks.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ def current_effective_deadline() -> float:
139139
Return the nearest deadline among all the cancel scopes effective for the current
140140
task.
141141
142-
:return: a clock value from the event loop's internal clock (``float('inf')`` if
143-
there is no deadline in effect)
142+
:return: a clock value from the event loop's internal clock (or ``float('inf')`` if
143+
there is no deadline in effect, or ``float('-inf')`` if the current scope has
144+
been cancelled)
144145
:rtype: float
145146
146147
"""

src/anyio/abc/_eventloop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def current_effective_deadline(cls) -> float:
146146
147147
:return:
148148
- a clock value from the event loop's internal clock
149-
- ``'inf`` if there is no deadline in effect
149+
- ``inf`` if there is no deadline in effect
150150
- ``-inf`` if the current scope has been cancelled
151151
:rtype: float
152152
"""

tests/test_taskgroups.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import math
45
import sys
56
import time
67
from collections.abc import AsyncGenerator, Coroutine, Generator
@@ -527,6 +528,9 @@ async def test_cancel_from_shielded_scope() -> None:
527528
with CancelScope(shield=True) as inner_scope:
528529
assert inner_scope.shield
529530
tg.cancel_scope.cancel()
531+
assert current_effective_deadline() == math.inf
532+
533+
assert current_effective_deadline() == -math.inf
530534

531535
with pytest.raises(get_cancelled_exc_class()):
532536
await sleep(0.01)
@@ -535,6 +539,16 @@ async def test_cancel_from_shielded_scope() -> None:
535539
await sleep(0.01)
536540

537541

542+
async def test_cancel_shielded_scope() -> None:
543+
with CancelScope(shield=True) as cancel_scope:
544+
assert cancel_scope.shield
545+
cancel_scope.cancel()
546+
assert current_effective_deadline() == -math.inf
547+
548+
with pytest.raises(get_cancelled_exc_class()):
549+
await sleep(0)
550+
551+
538552
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
539553
async def test_cancel_host_asyncgen() -> None:
540554
done = False

0 commit comments

Comments
 (0)