From 24bb8f7cb7a60366384356f508ea38f828f176ae Mon Sep 17 00:00:00 2001 From: julien Date: Sat, 2 Feb 2019 20:39:30 +0100 Subject: [PATCH] add flag for sigint signal handler --- proxybroker/api.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/proxybroker/api.py b/proxybroker/api.py index fa432e8..e8a7a14 100644 --- a/proxybroker/api.py +++ b/proxybroker/api.py @@ -51,7 +51,7 @@ class Broker: def __init__(self, queue=None, timeout=8, max_conn=200, max_tries=3, judges=None, providers=None, verify_ssl=False, loop=None, - **kwargs): + stop__broker_on_sigint=True, **kwargs): self._loop = loop or asyncio.get_event_loop() self._proxies = queue or asyncio.Queue(loop=self._loop) self._resolver = Resolver(loop=self._loop) @@ -88,13 +88,13 @@ def __init__(self, queue=None, timeout=8, max_conn=200, max_tries=3, self._judges = judges self._providers = [p if isinstance(p, Provider) else Provider(p) for p in (providers or PROVIDERS)] - - try: - self._loop.add_signal_handler(signal.SIGINT, self.stop) - # add_signal_handler() is not implemented on Win - # https://docs.python.org/3.5/library/asyncio-eventloops.html#windows - except NotImplementedError: - pass + if stop__broker_on_sigint: + try: + self._loop.add_signal_handler(signal.SIGINT, self.stop) + # add_signal_handler() is not implemented on Win + # https://docs.python.org/3.5/library/asyncio-eventloops.html#windows + except NotImplementedError: + pass async def grab(self, *, countries=None, limit=0): """Gather proxies from the providers without checking.