我使用Django、Celery和Channels(带有redis后端(来处理基于Dajango的后端中的任务。最近,随着事态的发展,我面临的问题是:
ValueError("select((中的文件描述符超出范围",(
Traceback (most recent call last):
File "/home/cbt/backend/venv/lib/python3.6/site-packages/asgiref/sync.py", line 46, in __call__
loop.run_until_complete(self.main_wrap(args, kwargs, call_result))
File "/usr/lib/python3.6/asyncio/base_events.py", line 471, in run_until_complete
self.run_forever()
File "/usr/lib/python3.6/asyncio/base_events.py", line 438, in run_forever
self._run_once()
File "/usr/lib/python3.6/asyncio/base_events.py", line 1415, in _run_once
event_list = self._selector.select(timeout)
File "/usr/lib/python3.6/selectors.py", line 323, in select
r, w, _ = self._select(self._readers, self._writers, [], timeout)
File "/home/cbt/backend/venv/lib/python3.6/site-packages/gevent/monkey.py", line 831, in _select
return select.select(*args, **kwargs)
File "/home/cbt/backend/venv/lib/python3.6/site-packages/gevent/select.py", line 145, in select
sel_results = _original_select(rlist, wlist, xlist, 0)
ValueError: filedescriptor out of range in select()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/cbt/backend/venv/lib/python3.6/site-packages/celery/app/trace.py", line 385, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/cbt/backend/venv/lib/python3.6/site-packages/celery/app/trace.py", line 648, in __protected_call__
return self.run(*args, **kwargs)
File "/home/cbt/backend/cbproj/tasks/tasks.py", line 1095, in start_new_subgame_timer
add_users_to_subgame(game, game_type)
File "/home/cbt/backend/cbproj/tasks/tasks.py", line 1405, in add_users_to_subgame
async_to_sync(group_send_empty_subgame_audio_game_response)(game, game_type)
File "/home/cbt/backend/venv/lib/python3.6/site-packages/asgiref/sync.py", line 50, in __call__
loop.run_until_complete(loop.shutdown_asyncgens())
File "/usr/lib/python3.6/asyncio/base_events.py", line 471, in run_until_complete
self.run_forever()
File "/usr/lib/python3.6/asyncio/base_events.py", line 438, in run_forever
self._run_once()
File "/usr/lib/python3.6/asyncio/base_events.py", line 1415, in _run_once
event_list = self._selector.select(timeout)
File "/usr/lib/python3.6/selectors.py", line 323, in select
r, w, _ = self._select(self._readers, self._writers, [], timeout)
File "/home/cbt/backend/venv/lib/python3.6/site-packages/gevent/monkey.py", line 831, in _select
return select.select(*args, **kwargs)
File "/home/cbt/backend/venv/lib/python3.6/site-packages/gevent/select.py", line 145, in select
sel_results = _original_select(rlist, wlist, xlist, 0)
ValueError: filedescriptor out of range in select()
我正在使用以下软件包和python 3.6
- 芹菜==4.3.0
- 通道==3.0.2
- 通道redis==3.2.0
此外,当我使用django通道库提供的async_to_sync
函数时也会发生这种情况(但不是每次都发生(。这方面有什么办法吗?
我打开文件的限制是20000,我绝对不会超过这个限制。
根据您的错误日志,我猜您的项目中使用了monkey.patch_all
,如下所示:
from gevent import monkey
monkey.patch_all()
在旧的gevent版本(<1.5.0(中,monkey.patch_all()
设置DefaultSelector = SelectSelector
。当fileno>1024,SelectSelector将引发这样的ValueError。你可以检查这个问题,并将gevent升级到新版本(1.5.0+(,这样你就可以解决这个问题。
Gevent的monkey.patch在新版本中设置了DefaultSelector = PollSelector
。