请问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...

编橙之家文章,

评论关闭