diff --git a/proxybroker/api.py b/proxybroker/api.py index 71b61fe..135b61e 100644 --- a/proxybroker/api.py +++ b/proxybroker/api.py @@ -64,7 +64,7 @@ def __init__( stop_broker_on_sigint=True, **kwargs, ): - self._loop = loop or asyncio.get_event_loop_policy().get_event_loop() + self._loop = loop self._proxies = queue or asyncio.Queue() self._resolver = Resolver(loop=self._loop) self._timeout = timeout diff --git a/proxybroker/checker.py b/proxybroker/checker.py index bedad3f..a510db3 100644 --- a/proxybroker/checker.py +++ b/proxybroker/checker.py @@ -43,7 +43,7 @@ def __init__( self._strict = strict self._dnsbl = dnsbl or [] self._types = types or {} - self._loop = loop or asyncio.get_event_loop() + self._loop = loop self._resolver = Resolver(loop=self._loop) self._req_http_proto = not types or bool( diff --git a/proxybroker/cli.py b/proxybroker/cli.py index 22bb3bd..1ab4e1e 100644 --- a/proxybroker/cli.py +++ b/proxybroker/cli.py @@ -387,7 +387,7 @@ def cli(args=sys.argv[1:]): ns.types.remove('HTTP') ns.types.append(('HTTP', ns.anon_lvl)) - loop = asyncio.get_event_loop_policy().get_event_loop() + loop = asyncio.new_event_loop() proxies = asyncio.Queue() broker = Broker( proxies, @@ -443,6 +443,7 @@ def cli(args=sys.argv[1:]): try: if tasks: + asyncio.set_event_loop(loop) loop.run_until_complete(asyncio.gather(*tasks)) if ns.show_stats: broker.show_stats(verbose=True) diff --git a/proxybroker/judge.py b/proxybroker/judge.py index d7dfe84..4f1bbe8 100644 --- a/proxybroker/judge.py +++ b/proxybroker/judge.py @@ -29,7 +29,7 @@ def __init__(self, url, timeout=8, verify_ssl=False, loop=None): self.marks = {'via': 0, 'proxy': 0} self.timeout = timeout self.verify_ssl = verify_ssl - self._loop = loop or asyncio.get_event_loop() + self._loop = loop self._resolver = Resolver(loop=self._loop) def __repr__(self): diff --git a/proxybroker/providers.py b/proxybroker/providers.py index 17b67ab..6e9adf8 100644 --- a/proxybroker/providers.py +++ b/proxybroker/providers.py @@ -45,7 +45,7 @@ def __init__( self._proxies = set() # concurrent connections on the current provider self._sem_provider = asyncio.Semaphore(max_conn) - self._loop = loop or asyncio.get_event_loop() + self._loop = loop @property def proxies(self): diff --git a/proxybroker/resolver.py b/proxybroker/resolver.py index 10afb42..5f94582 100644 --- a/proxybroker/resolver.py +++ b/proxybroker/resolver.py @@ -44,7 +44,7 @@ class Resolver: def __init__(self, timeout=5, loop=None): self._timeout = timeout - self._loop = loop or asyncio.get_event_loop() + self._loop = loop self._resolver = aiodns.DNSResolver(loop=self._loop) @staticmethod diff --git a/proxybroker/server.py b/proxybroker/server.py index b969c5e..16c2c2c 100644 --- a/proxybroker/server.py +++ b/proxybroker/server.py @@ -131,7 +131,7 @@ def __init__( ): self.host = host self.port = int(port) - self._loop = loop or asyncio.get_event_loop() + self._loop = loop self._timeout = timeout self._max_tries = max_tries self._backlog = backlog