Skip to content

Commit aef8c57

Browse files
committed
Avoid adding signal handlers to the event loop at connection
1. Because if someone runs pylibjuju in an off-main thread, then add_signal_handler will (rightfully) complain (see issue #1010). 2. Pylibjuju as a library shouldn't enforce a certain way of handling signals. Clients should install their handlers however they wanna handle them. Fixes #1010
1 parent 32ce250 commit aef8c57

1 file changed

Lines changed: 0 additions & 10 deletions

File tree

juju/client/connection.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import json
66
import logging
77
import ssl
8-
import signal
98
import urllib.request
109
import weakref
1110
from http.client import HTTPSConnection
@@ -425,10 +424,6 @@ def _exit_tasks():
425424
for task in jasyncio.all_tasks():
426425
task.cancel()
427426

428-
loop = jasyncio.get_running_loop()
429-
for sig in (signal.SIGINT, signal.SIGTERM):
430-
loop.add_signal_handler(sig, _exit_tasks)
431-
432427
return (await websockets.connect(
433428
url,
434429
ssl=self._get_ssl(cacert),
@@ -473,11 +468,6 @@ async def close(self, to_reconnect=False):
473468
if self.proxy is not None:
474469
self.proxy.close()
475470

476-
# Remove signal handlers
477-
loop = jasyncio.get_running_loop()
478-
for sig in (signal.SIGINT, signal.SIGTERM):
479-
loop.remove_signal_handler(sig)
480-
481471
async def _recv(self, request_id):
482472
if not self.is_open:
483473
raise websockets.exceptions.ConnectionClosed(0, 'websocket closed')

0 commit comments

Comments
 (0)