Skip to content

Commit d3467f8

Browse files
authored
Allow running conjure-python-client on Windows (#177)
Allow running conjure-python-client on Windows
1 parent 0c40fa6 commit d3467f8

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

conjure_python_client/_http/requests_client.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import random
2727
import requests
2828
import socket
29-
import sys
3029

3130

3231
T = TypeVar("T")
@@ -55,13 +54,15 @@
5554
socket.SO_KEEPALIVE,
5655
1,
5756
) # Enable keep alive.
58-
SOCKET_KEEP_INTVL = (
59-
socket.SOL_TCP,
60-
socket.TCP_KEEPINTVL,
61-
120,
62-
) # Interval of 120s between individual keepalive probes.
63-
KEEP_ALIVE_SOCKET_OPTIONS = [SOCKET_KEEP_ALIVE, SOCKET_KEEP_INTVL]
64-
if sys.platform != "darwin":
57+
KEEP_ALIVE_SOCKET_OPTIONS = [SOCKET_KEEP_ALIVE]
58+
if hasattr(socket, "TCP_KEEPINTVL"):
59+
SOCKET_KEEP_INTVL = (
60+
socket.SOL_TCP,
61+
socket.TCP_KEEPINTVL,
62+
120,
63+
) # Interval of 120s between individual keepalive probes.
64+
KEEP_ALIVE_SOCKET_OPTIONS.append(SOCKET_KEEP_INTVL)
65+
if hasattr(socket, "TCP_KEEPIDLE"):
6566
SOCKET_KEEP_IDLE = (
6667
socket.SOL_TCP,
6768
socket.TCP_KEEPIDLE,

test/_http/test_requests_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import copy
22
import pickle
3-
import sys
3+
import socket
44

55
from conjure_python_client._http.requests_client import (
66
ConjureHTTPError,
77
SOCKET_KEEP_ALIVE,
8-
SOCKET_KEEP_INTVL,
98
TransportAdapter,
109
)
1110
from requests.exceptions import HTTPError
1211

13-
if sys.platform != "darwin":
12+
if hasattr(socket, "TCP_KEEPINTVL"):
13+
from conjure_python_client._http.requests_client import SOCKET_KEEP_INTVL
14+
if hasattr(socket, "TCP_KEEPIDLE"):
1415
from conjure_python_client._http.requests_client import SOCKET_KEEP_IDLE
1516

1617

@@ -28,8 +29,9 @@ def test_keep_alive_passes_correct_options():
2829
max_retries=12, enable_keep_alive=True
2930
).poolmanager.connection_pool_kw["socket_options"]
3031
assert SOCKET_KEEP_ALIVE in socket_options
31-
assert SOCKET_KEEP_INTVL in socket_options
32-
if sys.platform != "darwin":
32+
if hasattr(socket, "TCP_KEEPINTVL"):
33+
assert SOCKET_KEEP_INTVL in socket_options
34+
if hasattr(socket, "TCP_KEEPIDLE"):
3335
assert SOCKET_KEEP_IDLE in socket_options
3436

3537

0 commit comments

Comments
 (0)