Skip to content

Commit

Permalink
fix: avoid deprecated asyncio.TimeoutError on 3.11+
Browse files Browse the repository at this point in the history
  • Loading branch information
tazlin committed Feb 2, 2024
1 parent 637fd6b commit 09a070f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions horde_worker_regen/process_management/process_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import asyncio.exceptions
import base64
import collections
import datetime
Expand All @@ -17,16 +18,14 @@
from multiprocessing.context import BaseContext
from multiprocessing.synchronize import Lock as Lock_MultiProcessing
from multiprocessing.synchronize import Semaphore
from asyncio.exceptions import TimeoutError as AsyncioTimeoutError
from aiohttp.client_exceptions import ClientOSError as AsyncioClientOSError

import aiohttp
import aiohttp.client_exceptions
import PIL
import PIL.Image
import psutil
import yarl
from aiohttp import ClientSession
from aiohttp.client_exceptions import ClientError
from horde_model_reference.meta_consts import MODEL_REFERENCE_CATEGORY, STABLE_DIFFUSION_BASELINE_CATEGORY
from horde_model_reference.model_reference_manager import ModelReferenceManager
from horde_model_reference.model_reference_records import StableDiffusion_ModelReference
Expand Down Expand Up @@ -72,12 +71,20 @@
)
from horde_worker_regen.process_management.worker_entry_points import start_inference_process, start_safety_process

# This is due to Linux/Windows differences in the multiprocessing module
try:
from multiprocessing.connection import PipeConnection as Connection # type: ignore
except Exception:
from multiprocessing.connection import Connection # type: ignore


# As of 3.11, asyncio.TimeoutError is deprecated and is an alias for builtins.TimeoutError
_async_client_exceptions: tuple[type[Exception], ...] = (TimeoutError, aiohttp.client_exceptions.ClientError, OSError)

if sys.version_info == (3, 10):
_async_client_exceptions = (asyncio.exceptions.TimeoutError, aiohttp.client_exceptions.ClientError, OSError)


class HordeProcessInfo:
"""Contains information about a horde child process."""

Expand Down Expand Up @@ -1685,8 +1692,9 @@ async def submit_single_generation(self, new_submit: PendingSubmitJob) -> Pendin
logger.error(f"Failed to upload image to R2: {response}")
new_submit.retry()
return new_submit
except (TimeoutError, AsyncioTimeoutError, AsyncioClientOSError):
except _async_client_exceptions as e:
logger.warning("Generation Submit to AI Horde timed out. Will retry.")
logger.debug(f"{type(e).__name__}: {e}")
new_submit.retry()
return new_submit
metadata = []
Expand Down Expand Up @@ -2224,7 +2232,7 @@ async def api_get_user_info(self) -> None:

logger.info(f"Worker Kudos Accumulated: {self.user_info.kudos_details.accumulated:.2f}")

except ClientError as e:
except _async_client_exceptions as e:
self._user_info_failed = True
self._user_info_failed_reason = f"HTTP error (({type(e).__name__}) {e})"

Expand Down

0 comments on commit 09a070f

Please sign in to comment.