请问Python tornado异步tcp服务器一些问题,pythontornado,大家好!我有一段torn
请问Python tornado异步tcp服务器一些问题,pythontornado,大家好!我有一段torn
大家好!
我有一段tornado异步tcp服务器的代码,tcp服务器向客户端发送命令,遇到一些问题.
#! /usr/bin/env python#coding=utf-8from tornado.tcpserver import TCPServerfrom tornado.ioloop import IOLoopfrom ctypes import *import structfrom const import *from systemModel import *class TcpConnection(object): def __init__(self,stream,address): self._stream=stream self._address=address self._stream.set_close_callback(self.on_close) self.getSystemInfo() self.getSystemInfo() def on_close(self): print("the monitored %d has left",self._address) def getSystemInfo(self): commandType=Command.SYSTEMINFO commandInfo=Command.NOCOMMANDINFO data=struct.pack(FormatStr.COMMANDINFO,commandType,commandInfo.encode('utf-8')) self._stream.write(data) self._stream.read_bytes(SystemInfo.len_whole,setSystemInfo)class MonitorServer(TCPServer): def handle_stream(self,stream,address): print("new connection",address,stream) TcpConnection(stream,address)if __name__=='__main__': print('server start .....') server=MonitorServer() server.listen(20000) IOLoop.instance().start()
上面有2个self.getSystemInfo(),我的意思是想,能否一下丢出几个命令,比如传文件,传信息等.但是上面的代码会报错.错误信息如下:
ERROR:tornado.application:Error in connection callbackTraceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/tornado/tcpserver.py", line 269, in _handle_connection future = self.handle_stream(stream, address) File "/home/zz/PycharmProjects/monitor/server.py", line 64, in handle_stream TcpConnection(stream,address) File "/home/zz/PycharmProjects/monitor/server.py", line 18, in __init__ self.getSystemInfo() File "/home/zz/PycharmProjects/monitor/server.py", line 32, in getSystemInfo self._stream.read_bytes(SystemInfo.len_whole,setSystemInfo) File "/usr/local/lib/python3.4/dist-packages/tornado/iostream.py", line 303, in read_bytes future = self._set_read_callback(callback) File "/usr/local/lib/python3.4/dist-packages/tornado/iostream.py", line 658, in _set_read_callback assert self._read_callback is None, "Already reading"AssertionError: Already reading
这个错误信息,是不是前一个self.getSystemInfo()还没读完,后一个self.getSystemInfo()就要开始读了?我要怎样去解决这样的冲突呢
已解决 http://stackoverflow.com/questions/31344127/how-to-process-multiple-co...
编橙之家文章,
相关内容
- Python tornado nginx静态文件配置怎么解决,tornadonginx,访问
- 想在tcp server使用ornado.gen.coroutine遇到问题,,tcp server的
- 关于端口程序监听问题寻求帮助,端口程序监听寻求
- Python源码中输出结果问题,python源码输出结果,def func
- 使用用户关系表中外键获取User应该怎么做,关系表中外
- Python书箱《flask web开发》第七章test问题求助,,Asserti
- Python flask调用PHP脚本执行时失败找不到原因,pythonfla
- Python2.7在做连接mysql数据库操作时崩溃啦,python2.7mysq
- 请问有通用性较强的RBAC模块可以用于web吗,rbacweb,我在
- Python flask代码优化求大神指点,pythonflask,@bp.route(/s
评论关闭