Skip to content

Commit a7b1e51

Browse files
authored
Switch usage of asyncio.wait_for to async_timeout (#337)
* 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 * adjust ci
1 parent 0994182 commit a7b1e51

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
if python --version 2>&1 | grep -q "Python 2"; then pip install mock rsa==4.0; fi
3131
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3232
pip install .
33-
if python --version 2>&1 | grep -q "Python 3.7" || python --version 2>&1 | grep -q "Python 3.8" || python --version 2>&1 | grep -q "Python 3.9" || python --version 2>&1 | grep -q "Python 3.10"; then pip install aiofiles adb-shell[usb]; fi
33+
if python --version 2>&1 | grep -q "Python 3.7" || python --version 2>&1 | grep -q "Python 3.8" || python --version 2>&1 | grep -q "Python 3.9" || python --version 2>&1 | grep -q "Python 3.10"; then pip install aiofiles async_timeout adb-shell[usb]; fi
3434
- name: Check formatting with black
3535
run: |
3636
if python --version 2>&1 | grep -q "Python 3.7" || python --version 2>&1 | grep -q "Python 3.8" || python --version 2>&1 | grep -q "Python 3.9" || python --version 2>&1 | grep -q "Python 3.10"; then pip install black && make lint-black; fi

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="[email protected]",
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)