@@ -43,6 +43,8 @@ class Broker:
4343 (optional) Flag indicating whether to check the SSL certificates.
4444 Set to True to check ssl certifications
4545 :param loop: (optional) asyncio compatible event loop
46+ :param stop_broker_on_sigint: (optional) whether set SIGINT signal on broker object.
47+ Useful for a thread other than main thread.
4648
4749 .. deprecated:: 0.2.0
4850 Use :attr:`max_conn` and :attr:`max_tries` instead of
@@ -59,6 +61,7 @@ def __init__(
5961 providers = None ,
6062 verify_ssl = False ,
6163 loop = None ,
64+ stop_broker_on_sigint = True ,
6265 ** kwargs ,
6366 ):
6467 self ._loop = loop or asyncio .get_event_loop ()
@@ -101,13 +104,13 @@ def __init__(
101104 p if isinstance (p , Provider ) else Provider (p )
102105 for p in (providers or PROVIDERS )
103106 ]
104-
105- try :
106- self ._loop .add_signal_handler (signal .SIGINT , self .stop )
107- # add_signal_handler() is not implemented on Win
108- # https://docs.python.org/3.5/library/asyncio-eventloops.html#windows
109- except NotImplementedError :
110- pass
107+ if stop_broker_on_sigint :
108+ try :
109+ self ._loop .add_signal_handler (signal .SIGINT , self .stop )
110+ # add_signal_handler() is not implemented on Win
111+ # https://docs.python.org/3.5/library/asyncio-eventloops.html#windows
112+ except NotImplementedError :
113+ pass
111114
112115 async def grab (self , * , countries = None , limit = 0 ):
113116 """Gather proxies from the providers without checking.
0 commit comments