Skip to content

Commit 0d228fb

Browse files
committed
Switch usage of asyncio.wait_for to async_timeout
`asyncio.wait_for` creates another tasks which leads to some race conditions in cancelation and a performance hit cpython 3.12 will change the underlying implementation of `asyncio.wait_for` to use `asyncio.wait` but that is still a long way off for many people: python/cpython#98518
1 parent 0994182 commit 0d228fb

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

androidtv/adb_manager/adb_manager_async.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from adb_shell.auth.sign_pythonrsa import PythonRSASigner
1616
from adb_shell.constants import DEFAULT_PUSH_MODE, DEFAULT_READ_TIMEOUT_S
1717
import aiofiles
18+
import async_timeout
1819
from ppadb.client import Client
1920

2021
from ..constants import (
@@ -164,7 +165,8 @@ async def _acquire(lock, timeout=DEFAULT_LOCK_TIMEOUT_S):
164165
try:
165166
acquired = False
166167
try:
167-
acquired = await asyncio.wait_for(lock.acquire(), timeout)
168+
async with async_timeout.timeout(timeout):
169+
acquired = await lock.acquire()
168170
if not acquired:
169171
raise LockNotAcquiredException
170172
yield acquired

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
author_email="jefflirion@users.noreply.github.com",
1616
packages=["androidtv", "androidtv.adb_manager", "androidtv.basetv", "androidtv.androidtv", "androidtv.firetv"],
1717
install_requires=["adb-shell>=0.4.0", "pure-python-adb>=0.3.0.dev0"],
18-
extras_require={"async": ["aiofiles>=0.4.0"], "usb": ["adb-shell[usb]>=0.4.0"]},
18+
extras_require={"async": ["aiofiles>=0.4.0", "async_timeout>=3.0.0"], "usb": ["adb-shell[usb]>=0.4.0"]},
1919
classifiers=[
2020
"License :: OSI Approved :: MIT License",
2121
"Operating System :: OS Independent",

0 commit comments

Comments
 (0)