lexiforest / curl_cffi

Python binding for curl-impersonate fork via cffi. A http client that can impersonate browser tls/ja3/http2 fingerprints.
https://curl-cffi.readthedocs.io/
MIT License
2.52k stars 266 forks source link

[BUG] ValueError: too many file descriptors in select() #338

Closed luanon404 closed 4 months ago

luanon404 commented 4 months ago

possible fix, change from asyncio.SelectorEventLoop into asyncio.ProactorEventLoop, when i set ProactorEventLoop loop, i got


Traceback (most recent call last):
  File "F:\pythonxxx\src\a.py", line 343, in _generate_mail
    async with AsyncSession(**session_params) as session:
  File "F:\pythonxxx\.venv\Lib\site-packages\curl_cffi\requests\session.py", line 994, in __aexit__
    await self.close()
  File "F:\pythonxxx\.venv\Lib\site-packages\curl_cffi\requests\session.py", line 999, in close
    await self.acurl.close()
  File "F:\pythonxxx\.venv\Lib\site-packages\curl_cffi\aio.py", line 155, in close
    await self._checker
RuntimeError: Task <Task cancelling name='Task-318' coro=<Test.run.<locals>.worker() running at F:\pythonxxx\src\a.py:416> cb=[as_completed.<locals>._on_completion() at D:\Python\Python312\Lib\asyncio\tasks.py:618, gather.<locals>._done_callback() at D:\Python\Python312\Lib\asyncio\tasks.py:767]> got Future <Task cancelling name='Task-2183' coro=<AsyncCurl._force_timeout() running at F:\pythonxxx\.venv\Lib\site-packages\curl_cffi\aio.py:176>> attached to a different loop
luanon404 commented 4 months ago

Im using Windows so should use ProactorEventLoop instead of SelectorEventLoop

perklet commented 4 months ago

From the traceback, it seems that you switched loop implementation from the middle. You should select loop as early as possible.

luanon404 commented 4 months ago

From the traceback, it seems that you switched loop implementation from the middle. You should select loop as early as possible.

yes, because on windows, SelectorEventLoop limit amount of pipe can open, so they made ProactorEventLoop, i dont know can i use ProactorEventLoop instead of SelectorEventLoop? or change something in the code?

luanon404 commented 4 months ago

i tried pass ProactorEventLoop loop into session class to bypass the limit, but its say the future waited in different loop

luanon404 commented 4 months ago

so i wonder that u not use same loop for all code

perklet commented 4 months ago

If you want to use ProactorLoop, you don’t need to do anything, since it’s the default one.

luanon404 commented 4 months ago

If you want to use ProactorLoop, you don’t need to do anything, since it’s the default one.

but i got this when run like 700 threads,

Exception in thread Tornado selector:
Traceback (most recent call last):
  File "D:\Python\Python312\Lib\threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "D:\Python\Python312\Lib\threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "F:\python\MicrosoftOutlook\.venv\Lib\site-packages\curl_cffi\_asyncio_selector.py", line 201, in _run_select
    rs, ws, xs = select.select(to_read, to_write, to_write)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many file descriptors in select()

still use SelectorEventLoop , so its not default ProactorEventLoop ?

luanon404 commented 4 months ago

i dont know why but i solved by add time.sleep(0.01) before select command, image

luanon404 commented 4 months ago

maybe its running too fast before it data coming