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 asyncio
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import sys
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
|
@ -136,8 +137,11 @@ class TelemetryService(Service):
|
||||||
await task
|
await task
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
current_task = asyncio.current_task()
|
current_task = asyncio.current_task()
|
||||||
|
if sys.version_info >= (3, 11):
|
||||||
if current_task and current_task.cancelling() > 0:
|
if current_task and current_task.cancelling() > 0:
|
||||||
raise
|
raise
|
||||||
|
elif current_task and hasattr(current_task, "_must_cancel") and current_task._must_cancel:
|
||||||
|
raise
|
||||||
|
|
||||||
async def stop(self) -> None:
|
async def stop(self) -> None:
|
||||||
if self.do_not_track or self._stopping:
|
if self.do_not_track or self._stopping:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue