File tree 6 files changed +26
-6
lines changed
6 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
41
41
- Fixed ``start_blocking_portal() `` raising an unwarranted
42
42
``RuntimeError: This portal is not running `` if a task raises an exception that causes
43
43
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)
44
46
45
47
**3.6.1 **
46
48
Original file line number Diff line number Diff line change @@ -1886,7 +1886,10 @@ def current_effective_deadline(cls) -> float:
1886
1886
deadline = math .inf
1887
1887
while cancel_scope :
1888
1888
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 :
1890
1893
break
1891
1894
else :
1892
1895
cancel_scope = cancel_scope ._parent_scope
Original file line number Diff line number Diff line change @@ -136,8 +136,8 @@ async def connect_tcp(
136
136
"""
137
137
Connect to a host using the TCP protocol.
138
138
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,
141
141
each one is tried until one connection attempt succeeds. If the first attempt does
142
142
not connected within 250 milliseconds, a second attempt is started using the next
143
143
address in the list, and so on. On IPv6 enabled systems, an IPv6 address (if
Original file line number Diff line number Diff line change @@ -139,8 +139,9 @@ def current_effective_deadline() -> float:
139
139
Return the nearest deadline among all the cancel scopes effective for the current
140
140
task.
141
141
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)
144
145
:rtype: float
145
146
146
147
"""
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ def current_effective_deadline(cls) -> float:
146
146
147
147
:return:
148
148
- 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
150
150
- ``-inf`` if the current scope has been cancelled
151
151
:rtype: float
152
152
"""
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import asyncio
4
+ import math
4
5
import sys
5
6
import time
6
7
from collections .abc import AsyncGenerator , Coroutine , Generator
@@ -527,6 +528,9 @@ async def test_cancel_from_shielded_scope() -> None:
527
528
with CancelScope (shield = True ) as inner_scope :
528
529
assert inner_scope .shield
529
530
tg .cancel_scope .cancel ()
531
+ assert current_effective_deadline () == math .inf
532
+
533
+ assert current_effective_deadline () == - math .inf
530
534
531
535
with pytest .raises (get_cancelled_exc_class ()):
532
536
await sleep (0.01 )
@@ -535,6 +539,16 @@ async def test_cancel_from_shielded_scope() -> None:
535
539
await sleep (0.01 )
536
540
537
541
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
+
538
552
@pytest .mark .parametrize ("anyio_backend" , ["asyncio" ])
539
553
async def test_cancel_host_asyncgen () -> None :
540
554
done = False
You can’t perform that action at this time.
0 commit comments