[#272] Support for external stop/restart control on the application #273

Merged
blacklight merged 18 commits from 272/external-proc-controller into master 2023-08-15 21:34:44 +02:00
1 changed files with 14 additions and 1 deletions
Showing only changes of commit 7157936b87 - Show all commits

View File

@ -15,7 +15,8 @@ import ssl
import urllib.request
from threading import Lock as TLock
from tempfile import gettempdir
from typing import Generator, Optional, Tuple, Union
import time
from typing import Generator, Optional, Tuple, Type, Union
from dateutil import parser, tz
from redis import Redis
@ -633,4 +634,16 @@ def get_default_pid_file() -> str:
return os.path.join(gettempdir(), 'platypush.pid')
def get_remaining_timeout(
timeout: Optional[float], start: float, cls: Union[Type[int], Type[float]] = float
) -> Optional[Union[int, float]]:
"""
Get the remaining timeout, given a start time.
"""
if timeout is None:
return None
return cls(max(0, timeout - (time.time() - start)))
# vim:sw=4:ts=4:et: