From ec0b08ebf0721eeb386745360d55e0877f8b632c Mon Sep 17 00:00:00 2001 From: lowercase00 <21188280+lowercase00@users.noreply.github.com> Date: Tue, 7 Mar 2023 23:39:04 -0300 Subject: [PATCH] bugfix: type annotations as str to allow Windows usage (#1852) --- rq/worker.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rq/worker.py b/rq/worker.py index a7f96f23..7852569c 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -4,7 +4,6 @@ import logging import math import os import random -import resource import signal import socket import sys @@ -19,6 +18,10 @@ from typing import (TYPE_CHECKING, Any, Callable, List, Optional, Tuple, Type, from uuid import uuid4 if TYPE_CHECKING: + try: + from resource import struct_rusage + except ImportError: + pass from redis import Redis from redis.client import Pipeline @@ -246,7 +249,7 @@ class Worker: disable_default_exception_handler: bool = False, prepare_for_work: bool = True, serializer=None, - work_horse_killed_handler: Optional[Callable[[Job, int, int, resource.struct_rusage], None]] = None + work_horse_killed_handler: Optional[Callable[[Job, int, int, 'struct_rusage'], None]] = None ): # noqa self.default_result_ttl = default_result_ttl self.worker_ttl = default_worker_ttl @@ -568,7 +571,7 @@ class Worker: else: raise - def wait_for_horse(self) -> Tuple[Optional[int], Optional[int], Optional[resource.struct_rusage]]: + def wait_for_horse(self) -> Tuple[Optional[int], Optional[int], Optional['struct_rusage']]: """Waits for the horse process to complete. Uses `0` as argument as to include "any child in the process group of the current process". """