2019-11-13 05:08:22 -05:00
|
|
|
# Test a task cancelling itself (currently unsupported)
|
|
|
|
|
|
|
|
try:
|
2023-06-08 02:01:38 -04:00
|
|
|
import asyncio
|
2019-11-13 05:08:22 -05:00
|
|
|
except ImportError:
|
2023-06-08 02:01:38 -04:00
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
2019-11-13 05:08:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
async def task():
|
|
|
|
print("task start")
|
|
|
|
global_task.cancel()
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
global global_task
|
|
|
|
global_task = asyncio.create_task(task())
|
|
|
|
try:
|
|
|
|
await global_task
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
print("main cancel")
|
|
|
|
print("main done")
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
asyncio.run(main())
|
|
|
|
except RuntimeError as er:
|
|
|
|
print(er)
|