Skip to content

Commit 58b5706

Browse files
Internal code restructure (no functional changes)
1 parent ef0f88f commit 58b5706

File tree

2 files changed

+25
-38
lines changed

2 files changed

+25
-38
lines changed

src/socketio/base_client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import itertools
22
import logging
3+
import signal
4+
import threading
35

46
from . import base_namespace
57
from . import packet
@@ -8,6 +10,24 @@
810
reconnecting_clients = []
911

1012

13+
def signal_handler(sig, frame): # pragma: no cover
14+
"""SIGINT handler.
15+
16+
Notify any clients that are in a reconnect loop to abort. Other
17+
disconnection tasks are handled at the engine.io level.
18+
"""
19+
for client in reconnecting_clients[:]:
20+
client._reconnect_abort.set()
21+
if callable(original_signal_handler):
22+
return original_signal_handler(sig, frame)
23+
else: # pragma: no cover
24+
# Handle case where no original SIGINT handler was present.
25+
return signal.default_int_handler(sig, frame)
26+
27+
28+
original_signal_handler = None
29+
30+
1131
class BaseClient:
1232
reserved_events = ['connect', 'connect_error', 'disconnect',
1333
'__disconnect_final']
@@ -16,6 +36,11 @@ def __init__(self, reconnection=True, reconnection_attempts=0,
1636
reconnection_delay=1, reconnection_delay_max=5,
1737
randomization_factor=0.5, logger=False, serializer='default',
1838
json=None, handle_sigint=True, **kwargs):
39+
global original_signal_handler
40+
if handle_sigint and original_signal_handler is None and \
41+
threading.current_thread() == threading.main_thread():
42+
original_signal_handler = signal.signal(signal.SIGINT,
43+
signal_handler)
1944
self.reconnection = reconnection
2045
self.reconnection_attempts = reconnection_attempts
2146
self.reconnection_delay = reconnection_delay

src/socketio/client.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import random
2-
import signal
3-
import threading
42

53
import engineio
64

@@ -9,24 +7,6 @@
97
from . import packet
108

119

12-
def signal_handler(sig, frame): # pragma: no cover
13-
"""SIGINT handler.
14-
15-
Notify any clients that are in a reconnect loop to abort. Other
16-
disconnection tasks are handled at the engine.io level.
17-
"""
18-
for client in base_client.reconnecting_clients[:]:
19-
client._reconnect_abort.set()
20-
if callable(original_signal_handler):
21-
return original_signal_handler(sig, frame)
22-
else: # pragma: no cover
23-
# Handle case where no original SIGINT handler was present.
24-
return signal.default_int_handler(sig, frame)
25-
26-
27-
original_signal_handler = None
28-
29-
3010
class Client(base_client.BaseClient):
3111
"""A Socket.IO client.
3212
@@ -87,24 +67,6 @@ class Client(base_client.BaseClient):
8767
fatal errors are logged even when
8868
``engineio_logger`` is ``False``.
8969
"""
90-
def __init__(self, reconnection=True, reconnection_attempts=0,
91-
reconnection_delay=1, reconnection_delay_max=5,
92-
randomization_factor=0.5, logger=False, serializer='default',
93-
json=None, handle_sigint=True, **kwargs):
94-
global original_signal_handler
95-
if handle_sigint and original_signal_handler is None and \
96-
threading.current_thread() == threading.main_thread():
97-
original_signal_handler = signal.signal(signal.SIGINT,
98-
signal_handler)
99-
100-
super().__init__(reconnection=reconnection,
101-
reconnection_attempts=reconnection_attempts,
102-
reconnection_delay=reconnection_delay,
103-
reconnection_delay_max=reconnection_delay_max,
104-
randomization_factor=randomization_factor,
105-
logger=logger, serializer=serializer, json=json,
106-
handle_sigint=handle_sigint, **kwargs)
107-
10870
def connect(self, url, headers={}, auth=None, transports=None,
10971
namespaces=None, socketio_path='socket.io', wait=True,
11072
wait_timeout=1):

0 commit comments

Comments
 (0)