CBV01 commited on
Commit
60dfd28
·
1 Parent(s): 237bda0

fix: resolve asyncio.timeout compatibility for Python < 3.11 and upgrade base image to Python 3.11

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. backend/main.py +17 -1
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM python:3.9-slim
2
 
3
  # Prepare environment
4
  RUN useradd -m -u 1000 user
 
1
+ FROM python:3.11-slim
2
 
3
  # Prepare environment
4
  RUN useradd -m -u 1000 user
backend/main.py CHANGED
@@ -44,6 +44,22 @@ from config import CORE_PROVIDER_ID, CORE_PROVIDER_KEY # type: ignore
44
  from auth import get_password_hash, verify_password, create_access_token, get_current_user_id # type: ignore
45
  import uvicorn # type: ignore
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  # Simple in-memory log buffer
48
  LOG_BUFFER = collections.deque(maxlen=100)
49
 
@@ -928,7 +944,7 @@ async def get_dialogs(req: FetchDialogsRequest, user_id: str = Depends(get_curre
928
  dialogs_list = []
929
  try:
930
  # use a long timeout, and include archived
931
- async with asyncio.timeout(60):
932
  async for dialog in client.iter_dialogs(limit=2000, archived=True, ignore_migrated=False):
933
  # Robust check for any container that isn't a single user
934
  if dialog.is_group or dialog.is_channel:
 
44
  from auth import get_password_hash, verify_password, create_access_token, get_current_user_id # type: ignore
45
  import uvicorn # type: ignore
46
 
47
+ # Backward-compatible async timeout helper (Python 3.11+ has asyncio.timeout natively)
48
+ if hasattr(asyncio, "timeout"):
49
+ async_timeout = asyncio.timeout
50
+ else:
51
+ @asynccontextmanager
52
+ async def async_timeout(delay: float):
53
+ loop = asyncio.get_running_loop()
54
+ task = asyncio.current_task()
55
+ handle = loop.call_later(delay, task.cancel)
56
+ try:
57
+ yield
58
+ except asyncio.CancelledError:
59
+ raise asyncio.TimeoutError()
60
+ finally:
61
+ handle.cancel()
62
+
63
  # Simple in-memory log buffer
64
  LOG_BUFFER = collections.deque(maxlen=100)
65
 
 
944
  dialogs_list = []
945
  try:
946
  # use a long timeout, and include archived
947
+ async with async_timeout(60):
948
  async for dialog in client.iter_dialogs(limit=2000, archived=True, ignore_migrated=False):
949
  # Robust check for any container that isn't a single user
950
  if dialog.is_group or dialog.is_channel: