constverum / ProxyBroker

Proxy [Finder | Checker | Server]. HTTP(S) & SOCKS :performing_arts:
http://proxybroker.readthedocs.io
Apache License 2.0
3.83k stars 1.08k forks source link

DeprecationWarning after setting new event loop #159

Open aleksul opened 4 years ago

aleksul commented 4 years ago

On python 3.6.10 after setting new event loop with asyncio.set_event_loop(asyncio.new_event_loop()) Got ~/venv-python36/lib/python3.6/site-packages/proxybroker/providers.py:78: DeprecationWarning: The object should be created from async function headers=get_headers(), cookies=self._cookies, loop=self._loop ~/venv-python36/lib/python3.6/site-packages/aiohttp/connector.py:731: DeprecationWarning: The object should be created from async function loop=loop) ~/venv-python36/lib/python3.6/site-packages/aiohttp/cookiejar.py:55: DeprecationWarning: The object should be created from async function super().__init__(loop=loop) However, I can get the list of proxies with broker.find() but after the program stops

the-owl commented 4 years ago

Try to import proxybroker after setting a new event loop.

I've stumbled upon a similar bug, I tried to run proxybroker in a Celery task (running with --pool=prefork) on macOS.

The solution is to create a new event loop, and import proxybroker after event loop initialization because proxybroker creates a built-in list of Provider objects with default event loop.

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
from proxybroker import Broker

# ...all your code...
aleksul commented 4 years ago

Try to import proxybroker after setting a new event loop.

I've stumbled upon a similar bug, I tried to run proxybroker in a Celery task (running with --pool=prefork) on macOS.

The solution is to create a new event loop, and import proxybroker after event loop initialization because proxybroker creates a built-in list of Provider objects with default event loop.

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
from proxybroker import Broker

# ...all your code...

Wow. Will try as soon as possible. I might be wrong but it seems to be not python-like, isn't it?