【发布时间】:2021-02-02 10:47:50
【问题描述】:
很久没有使用龙卷风了。我想要一个 websocket,它可以从运行龙卷风的主机的串行设备中获取更新。所以我尝试使用龙卷风进行多处理,但该进程无法访问龙卷风 websocket。我试图将它合并为协程,但似乎没有产生。
class WebApplication(tornado.web.Application):
def __init__(self):
handlers = [
(r'/', IndexPageHandler),
(r"/config", ConfigHandler),
(r"/shutdown", ShutdownHandler),
(r'/websocket', WebSocketHandler),
(r'/(.*)', tornado.web.StaticFileHandler, {'path': resourcesWeb})
]
settings = {
'debug': debug,
'static_path': resourcesWeb,
'template_path': 'templates'
}
tornado.web.Application.__init__(self, handlers, **settings)
@gen.coroutine
def serial_reader(self):
log('serial_reader: start')
done = False
while not done:
sh.read()
serial_data_from = str(sh.data)
if len(serial_data_from) > 0:
if debug:
log('serial read:' + serial_data_from)
yield [con.write_message(serial_data_from) for con in WebSocketHandler.connections]
yield gen.sleep(0.3)
log('serial_reader: exit')
Python 3.8.5,Tornad 6.1
我将如何正确且不断地使用来自 tornado 应用程序外部的数据更新 websocket
【问题讨论】:
标签: python-3.x tornado