Skip to content

Commit

Permalink
Initialize the client's SIGINT signal handler if a client is created (F…
Browse files Browse the repository at this point in the history
…ixes #424)
  • Loading branch information
miguelgrinberg committed Feb 15, 2020
1 parent 2a54f6c commit dc89963
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion socketio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import random
import signal
import threading

import engineio
import six
Expand All @@ -25,7 +26,7 @@ def signal_handler(sig, frame): # pragma: no cover
return original_signal_handler(sig, frame)


original_signal_handler = signal.signal(signal.SIGINT, signal_handler)
original_signal_handler = None


class Client(object):
Expand Down Expand Up @@ -82,6 +83,11 @@ def __init__(self, reconnection=True, reconnection_attempts=0,
reconnection_delay=1, reconnection_delay_max=5,
randomization_factor=0.5, logger=False, binary=False,
json=None, **kwargs):
global original_signal_handler
if original_signal_handler is None and \
threading.current_thread() == threading.main_thread():
original_signal_handler = signal.signal(signal.SIGINT,
signal_handler)
self.reconnection = reconnection
self.reconnection_attempts = reconnection_attempts
self.reconnection_delay = reconnection_delay
Expand Down

0 comments on commit dc89963

Please sign in to comment.