From aef8c57d91d81229b86f3b67eaafecb0dbb1782b Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 25 Jan 2024 08:51:49 -0700 Subject: [PATCH 1/2] 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 --- juju/client/connection.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/juju/client/connection.py b/juju/client/connection.py index ff6d8ee6b..0e3d9ef0c 100644 --- a/juju/client/connection.py +++ b/juju/client/connection.py @@ -5,7 +5,6 @@ import json import logging import ssl -import signal import urllib.request import weakref from http.client import HTTPSConnection @@ -425,10 +424,6 @@ def _exit_tasks(): for task in jasyncio.all_tasks(): task.cancel() - loop = jasyncio.get_running_loop() - for sig in (signal.SIGINT, signal.SIGTERM): - loop.add_signal_handler(sig, _exit_tasks) - return (await websockets.connect( url, ssl=self._get_ssl(cacert), @@ -473,11 +468,6 @@ async def close(self, to_reconnect=False): if self.proxy is not None: self.proxy.close() - # Remove signal handlers - loop = jasyncio.get_running_loop() - for sig in (signal.SIGINT, signal.SIGTERM): - loop.remove_signal_handler(sig) - async def _recv(self, request_id): if not self.is_open: raise websockets.exceptions.ConnectionClosed(0, 'websocket closed') From c6af97a0dc74120333d0ae033bb0103fe3134476 Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 25 Jan 2024 08:54:08 -0700 Subject: [PATCH 2/2] Fix typo in the makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e3d141e13..c2c25a304 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ run-unit-tests: lint .tox tox -e py3 .PHONY: run-integration-tests -run-unit-tests: lint .tox +run-integration-tests: lint .tox tox -e integration .PHONY: run-all-tests