Skip to content

Commit

Permalink
prevent asyncio from hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
ziloka committed Jan 17, 2024
1 parent dc944d6 commit dbd9fb9
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion proxybroker/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion proxybroker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion proxybroker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion proxybroker/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion proxybroker/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion proxybroker/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion proxybroker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dbd9fb9

Please sign in to comment.