-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathasync102_asyncio.py
More file actions
48 lines (39 loc) · 1.24 KB
/
async102_asyncio.py
File metadata and controls
48 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# type: ignore
# NOANYIO
# NOTRIO
# BASE_LIBRARY asyncio
from contextlib import asynccontextmanager
import asyncio
async def foo():
# asyncio.move_on_after does not exist, so this will raise an error
try:
...
finally:
with asyncio.move_on_after(deadline=30) as s:
s.shield = True
await foo() # error: 12, Statement("try/finally", lineno-5)
try:
pass
finally:
await foo() # error: 8, Statement("try/finally", lineno-3)
# asyncio.CancelScope does not exist, so this will raise an error
try:
pass
finally:
with asyncio.CancelScope(deadline=30, shield=True):
await foo() # error: 12, Statement("try/finally", lineno-4)
# TODO: I think this is the asyncio-equivalent, but functionality to ignore the error
# has not been implemented
try:
...
finally:
await asyncio.shield( # error: 8, Statement("try/finally", lineno-3)
asyncio.wait_for(foo())
)
# asyncio.TaskGroup *is* a source of cancellations (on exit)
async def foo_open_nursery_no_cancel():
try:
pass
finally:
async with asyncio.TaskGroup() as tg: # error: 8, Statement("try/finally", lineno-3)
...