我使用文档有一个非常简单的django项目设置 https://channels.readthedocs.io/en/stable/getting-started.html
在设置中:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgiref.inmemory.ChannelLayer",
"ROUTING": "core.routing.channel_routing",
},
}
在rounting.py中:
from channels.routing import route
from apps.prices.consumers import get_prices
channel_routing = [
route('get_prices', get_prices),
]
当我跑步时:
python manage.py runserver
打印:
2016-12-24 23:49:05,202 - INFO - worker - Listening on channels get_prices, http.request, websocket.connect, websocket.receive
2016-12-24 23:49:05,202 - INFO - worker - Listening on channels get_prices, http.request, websocket.connect, websocket.receive
2016-12-24 23:49:05,203 - INFO - worker - Listening on channels get_prices, http.request, websocket.connect, websocket.receive
2016-12-24 23:49:05,207 - INFO - server - Using busy-loop synchronous mode on channel layer
三名工人似乎出了问题,或者这是正常的? 但其他一切都很好。
建议的大问题
答案 0 :(得分:1)
当我运行./manage.py runserver
命令时,我默认会得到4个工作程序。
可能是通道runserver命令中的这一行 - https://github.com/django/channels/blob/a3f4e002eeebbf7c2412d9623e4e9809cfe32ba5/channels/management/commands/runserver.py#L80
要让单个工作人员运行,您可以使用渠道命令./manage.py runworker
。