From 2e91e049b3384762c5b555c97f16a84e5b93caf7 Mon Sep 17 00:00:00 2001 From: Danijar Hafner Date: Tue, 12 Nov 2024 17:36:51 -0800 Subject: [PATCH] Bypass user timeout for Mac TCP stack --- portal/__init__.py | 2 +- portal/client_socket.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/portal/__init__.py b/portal/__init__.py index f07b1e5..9e55272 100644 --- a/portal/__init__.py +++ b/portal/__init__.py @@ -1,4 +1,4 @@ -__version__ = '3.5.0' +__version__ = '3.5.1' import multiprocessing as mp try: diff --git a/portal/client_socket.py b/portal/client_socket.py index 2187e06..1883b2b 100644 --- a/portal/client_socket.py +++ b/portal/client_socket.py @@ -238,9 +238,10 @@ def _create(self): sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, after) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, every) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, fails) - sock.setsockopt( - socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, - 1000 * (after + every * fails)) + if hasattr(socket, 'TCP_USER_TIMEOUT'): # Linux + sock.setsockopt( + socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, + 1000 * (after + every * fails)) if sys.platform == 'darwin': sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPALIVE, every)