fix: make asyncio cancellation handling compatible with 3.10 (#4303)
Fix asyncio cancellation handling for Python 3.11 compatibility Co-authored-by: Christophe Bornet <cbornet@hotmail.com>
This commit is contained in:
parent
882f20d64f
commit
924e02f46d
1 changed files with 5 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
import asyncio
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
|
@ -136,7 +137,10 @@ class TelemetryService(Service):
|
|||
await task
|
||||
except asyncio.CancelledError:
|
||||
current_task = asyncio.current_task()
|
||||
if current_task and current_task.cancelling() > 0:
|
||||
if sys.version_info >= (3, 11):
|
||||
if current_task and current_task.cancelling() > 0:
|
||||
raise
|
||||
elif current_task and hasattr(current_task, "_must_cancel") and current_task._must_cancel:
|
||||
raise
|
||||
|
||||
async def stop(self) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue