Hi all,
I am using tornado tcpserver, and hit a problem when trying to add read callback.
Scenario is this:
I am the server, and there is one client connecting to me.
1. server sends something to client and read a response(has a read callback here), but , actually, the client hangs, won't send response to server now
2. server sends more thing to client again, and also, wait to read response(with a same callback here), client still hangs.
Snippet of related code:
def writeToDevice(self,data):
self.to_device = data
self.timer = Timer(settings.retry_interval,self.feedback_timeout_handle)
self.timer.start()
if self.retry == 0:
self._stream.write(data,self.wait_feedback)
else:
self._stream.write(data)
def write_cb(self):
self.read_feedback()
#self.timer.cancel()
def wait_feedback(self):
self._stream.read_until_regex('.*\*@\*', self.feed_ok)
def feed_ok(self,data):
if debug:
logger.log(10,'Received confirm from %s'%str(self._address))
self.timer.cancel()
Here comes the problem:
ERROR:tornado.application:Uncaught exception, closing connection.Traceback (most recent call last):File "/usr
b/python2.6/site-packages/tornado/iostream.py", line 341, in wrappercallback(*args)File "/usr
b/python2.6/site-packages/tornado/stack_context.py", line 331, in wrappedraise_exc_info(exc)File "/usr
b/python2.6/site-packages/tornado/stack_context.py", line 302, in wrappedret = fn(*args, **kwargs)File "deviceserver.py", line 227, in wait_feedbackself._stream.read_until_regex('.*\*@\*', self.feed_ok)File "/usr
b/python2.6/site-packages/tornado/iostream.py", line 142, in read_until_regexself._set_read_callback(callback)File "/usr
b/python2.6/site-packages/tornado/iostream.py", line 405, in _set_read_callbackassert not self._read_callback, "Already reading"AssertionError: Already reading
I see the iostream code here:
def _set_read_callback(self, callback):
assert not self._read_callback, "Already reading"
self._read_callback = stack_context.wrap(callback)
So, seems read callback limited to one?
Why?
Apperaciate for any helps.
Thanks.
Wesley