File tree Expand file tree Collapse file tree 5 files changed +24
-4
lines changed Expand file tree Collapse file tree 5 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
38
38
- Fixed ``start_blocking_portal() `` raising an unwarranted
39
39
``RuntimeError: This portal is not running `` if a task raises an exception that causes
40
40
the event loop to be closed
41
+ - Fixed ``current_effective_deadline() `` not returning ``-inf `` on asyncio when the
42
+ currently active cancel scope has been cancelled (PR by Ganden Schaffner)
41
43
42
44
**3.6.1 **
43
45
Original file line number Diff line number Diff line change @@ -1876,7 +1876,10 @@ def current_effective_deadline(cls) -> float:
1876
1876
deadline = math .inf
1877
1877
while cancel_scope :
1878
1878
deadline = min (deadline , cancel_scope .deadline )
1879
- if cancel_scope .shield :
1879
+ if cancel_scope ._cancel_called :
1880
+ deadline = - math .inf
1881
+ break
1882
+ elif cancel_scope .shield :
1880
1883
break
1881
1884
else :
1882
1885
cancel_scope = cancel_scope ._parent_scope
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