我使用websockets(AsyncWebsocketConsumer,django-channels)进行网络聊天。我正在使用celery来解析请求,但是每次我尝试将响应发送回使用者时,它都停止了,并且没有可调试的错误(对我而言)。
这种尝试给我下一个错误:
@shared_task
def execute(command, parameter, room_group_name):
if command == '/stock':
loop = asyncio.get_event_loop()
loop.run_until_complete(sendData(stock(parameter), "BOT", room_group_name))
return True
loop = asyncio.get_event_loop()
loop.run_until_complete(sendData("I do not understand that parameter", "BOT", room_group_name))
return True
from channels.layers import get_channel_layer
async def sendData(message, from_, room_group_name):
channel_layer = get_channel_layer()
import datetime
currentDT = datetime.datetime.now()
datetime = currentDT.strftime("%Y-%m-%d %H:%M:%S")
await channel_layer.group_send(
room_group_name,
{
'type': 'chat_message',
'username': from_,
'datetime': datetime,
'message': message
}
)
await asyncio.sleep(5)
错误:
[2019-05-12 18:01:15,491: ERROR/ForkPoolWorker-1] Task chat.tasks.execute[8a69afca-8173-46d0-84bc-4ee5ce7782ca] raised unexpected: OSError(9, 'Bad file descriptor')
Traceback (most recent call last):
File "/Users/juan/Documents/manu/dev/python_challenge/venv/lib/python3.6/site-packages/celery/app/trace.py", line 385, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/juan/Documents/manu/dev/python_challenge/venv/lib/python3.6/site-packages/celery/app/trace.py", line 648, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/juan/Documents/manu/dev/python_challenge/chat/tasks.py", line 14, in execute
loop.run_until_complete(sendData(stock(parameter), "BOT", room_group_name))
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 455, in run_until_complete
self.run_forever()
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 422, in run_forever
self._run_once()
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 1396, in _run_once
event_list = self._selector.select(timeout)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/selectors.py", line 577, in select
kev_list = self._kqueue.control(None, max_ev, timeout)
OSError: [Errno 9] Bad file descriptor
OSError:[Errno 9]错误的文件描述符,但是我找不到它的来源。
芹菜== 4.3.0