PyMySQL/Tornado-MySQL

IOLoop blocked

tkudla opened this issue · 3 comments

[W 150626 18:40:53 ioloop:326] IOLoop blocked for 1.000000 seconds in
      File "server.py", line 104, in <module>
        loop.start()
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/ioloop.py", line 784, in start
        self._run_callback(callback)
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/ioloop.py", line 568, in _run_callback
        ret = callback()
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/stack_context.py", line 314, in wrapped
        ret = fn(*args, **kwargs)
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 893, in <lambda>
        self.future, lambda f: self.run())
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 812, in run
        yielded = self.gen.send(value)
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado_mysql/connections.py", line 1066, in read
        yield self._read_result_packet(first_packet)
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 224, in wrapper
        Runner(result, future, yielded)
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 757, in __init__
        self.run()
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 812, in run
        yielded = self.gen.send(value)
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado_mysql/connections.py", line 1119, in _read_result_packet
        yield self._read_rowdata_packet()
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 224, in wrapper
        Runner(result, future, yielded)
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 757, in __init__
        self.run()
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 812, in run
        yielded = self.gen.send(value)
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado_mysql/connections.py", line 1155, in _read_rowdata_packet
        packet = yield self.connection._read_packet()
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 224, in wrapper
        Runner(result, future, yielded)
      File "/Users/tk/Projects/dr/lib/python2.7/site-packages/tornado/gen.py", line 746, in __init__
        self.running = False

self.running = False must not blocks. It just means signal handled here by chance.
How frequently this error happens?
Other MySQL connectors can connect to MySQL within 1sec everytime?

In my case it happens when there are 40-50k query results.

OK. This is not a blocking system call.
It just takes more than one second to process response data from MySQL.

You can use PyPy to make it faster.

Or you can use threadpool executer to avoid blocking while processing response data.
https://gist.github.com/methane/2185380#comment-1301483
If you use threadpool, I recommend you to use mysqlclient since it's faster.