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 #147)
  • Loading branch information
miguelgrinberg committed Dec 11, 2019
1 parent 9a3d645 commit 6534d32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion engineio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def signal_handler(sig, frame):
return signal.default_int_handler(sig, frame)


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


class Client(object):
Expand Down Expand Up @@ -76,6 +76,10 @@ def __init__(self,
json=None,
request_timeout=5,
ssl_verify=True):
global original_signal_handler
if original_signal_handler is None:
original_signal_handler = signal.signal(signal.SIGINT,
signal_handler)
self.handlers = {}
self.base_url = None
self.transports = None
Expand Down
5 changes: 4 additions & 1 deletion examples/client/asyncio/simple_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
loop = asyncio.get_event_loop()
eio = engineio.AsyncClient()
exit_event = asyncio.Event()
original_signal_handler = None


async def send_hello():
Expand Down Expand Up @@ -33,6 +34,8 @@ def on_message(data):
def signal_handler(sig, frame):
exit_event.set()
print('exiting')
if callable(original_signal_handler):
original_signal_handler(sig, frame)


async def start_client():
Expand All @@ -41,5 +44,5 @@ async def start_client():


if __name__ == '__main__':
signal.signal(signal.SIGINT, signal_handler)
original_signal_handler = signal.signal(signal.SIGINT, signal_handler)
loop.run_until_complete(start_client())
5 changes: 4 additions & 1 deletion examples/client/threads/simple_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

eio = engineio.Client()
exit_event = threading.Event()
original_signal_handler = None


def send_hello():
Expand All @@ -29,9 +30,11 @@ def on_message(data):
def signal_handler(sig, frame):
exit_event.set()
print('exiting')
if callable(original_signal_handler):
original_signal_handler(sig, frame)


if __name__ == '__main__':
signal.signal(signal.SIGINT, signal_handler)
original_signal_handler = signal.signal(signal.SIGINT, signal_handler)
eio.connect('http://localhost:5000')
eio.wait()

0 comments on commit 6534d32

Please sign in to comment.