diff --git a/pebble/common/types.py b/pebble/common/types.py index a0d0399..5da1ca8 100644 --- a/pebble/common/types.py +++ b/pebble/common/types.py @@ -179,6 +179,9 @@ class Consts: term_timeout: float = 3 """On UNIX once a SIGTERM signal is issued to a process, the amount of seconds to wait before issuing a SIGKILL signal.""" + channel_lock_timeout: float = 60 + """The process pool relies on a pipe protected by a lock. + The timeout when attempting to acquire the lock.""" try: diff --git a/pebble/pool/channel.py b/pebble/pool/channel.py index aa45f37..ca5675d 100644 --- a/pebble/pool/channel.py +++ b/pebble/pool/channel.py @@ -19,8 +19,10 @@ import select import multiprocessing +from typing import Any, Callable from contextlib import contextmanager -from typing import Any, Callable, Tuple + +from pebble.common import CONSTS class ChannelError(OSError): @@ -150,11 +152,15 @@ def __exit__(self, *_): def _make_acquire_method(self) -> Callable: def unix_acquire() -> bool: - return (self.reader_mutex.acquire(timeout=LOCK_TIMEOUT) and - self.writer_mutex.acquire(timeout=LOCK_TIMEOUT)) + return ( + self.reader_mutex.acquire(timeout=CONSTS.channel_lock_timeout) + and + self.writer_mutex.acquire(timeout=CONSTS.channel_lock_timeout) + ) def windows_acquire() -> bool: - return self.reader_mutex.acquire(timeout=LOCK_TIMEOUT) + return self.reader_mutex.acquire( + timeout=CONSTS.channel_lock_timeout) return unix_acquire if os.name != 'nt' else windows_acquire @@ -171,7 +177,7 @@ def windows_release(): @property @contextmanager def reader(self): - if self.reader_mutex.acquire(timeout=LOCK_TIMEOUT): + if self.reader_mutex.acquire(timeout=CONSTS.channel_lock_timeout): try: yield self finally: @@ -182,7 +188,7 @@ def reader(self): @property @contextmanager def writer(self): - if self.writer_mutex.acquire(timeout=LOCK_TIMEOUT): + if self.writer_mutex.acquire(timeout=CONSTS.channel_lock_timeout): try: yield self finally: @@ -192,4 +198,3 @@ def writer(self): MILLISECONDS = 1000 -LOCK_TIMEOUT = 60