Skip to content

Commit

Permalink
prevent asyncio hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
ziloka committed Jan 17, 2024
1 parent 1baa1c9 commit 95ba144
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.0
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ exclude = '''
| build
| dist
)
)
).0
'''

[tool.pytest.ini_options]
Expand Down

0 comments on commit 95ba144

Please sign in to comment.