From b54d44c5df38e2b6352933179e6fdc9281c42a31 Mon Sep 17 00:00:00 2001 From: Danijar Hafner Date: Wed, 18 Sep 2024 22:48:28 +0000 Subject: [PATCH] Add loop sleep parameters --- portal/__init__.py | 2 +- portal/client_socket.py | 4 ++++ portal/server_socket.py | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/portal/__init__.py b/portal/__init__.py index b820cba..f3f5c87 100644 --- a/portal/__init__.py +++ b/portal/__init__.py @@ -1,4 +1,4 @@ -__version__ = '3.4.2' +__version__ = '3.4.3' import multiprocessing as mp try: diff --git a/portal/client_socket.py b/portal/client_socket.py index df1d702..a6daa82 100644 --- a/portal/client_socket.py +++ b/portal/client_socket.py @@ -30,6 +30,7 @@ class Options: logging: bool = True logging_color: str = 'yellow' connect_wait: float = 0.1 + loop_sleep: float = 0.0 class ClientSocket: @@ -175,6 +176,9 @@ def _loop(self): [x() for x in self.callbacks_disc] continue + if self.options.loop_sleep: + time.sleep(self.options.loop_sleep) + if sock: sock.close() diff --git a/portal/server_socket.py b/portal/server_socket.py index 75930c1..5b8ff0a 100644 --- a/portal/server_socket.py +++ b/portal/server_socket.py @@ -3,6 +3,7 @@ import queue import selectors import socket +import time from . import buffers from . import contextlib @@ -31,6 +32,7 @@ class Options: max_send_queue: int = 4096 logging: bool = True logging_color: str = 'blue' + loop_sleep: float = 0.0 class ServerSocket: @@ -127,6 +129,8 @@ def _loop(self): # The client is gone but we may have buffered messages left to # read, so we keep the socket open until recv() fails. pass + if self.options.loop_sleep: + time.sleep(self.options.loop_sleep) except Exception as e: self.error = e