[tornado] Polling a Psycopg2 connection

88 views
Skip to first unread message

Frank Smit

unread,
Oct 5, 2012, 8:58:19 AM10/5/12
to python-...@googlegroups.com
Hi,

I've been rewriting Momoko and trying some new things and I
encountered a bug when implementing transactions. I've isolated the
code and reproduce the problem. It's probably me doing something
wrong, but I can't figure out what.

Here is the code:
https://gist.github.com/3839266

After a connection is made, the `io_callback` is called a fe times
(around 5 times). Then a query is made and `io_callback` is called
constantly. It doesn't stop even after the state is `POLL_OK`.

Here is a snippet of the output. The number show the times
`io_callback` has been caled before I aborted the script.

53687 POLL_OK IOLoop.NONE
Test conn: <__main__.Connection object at 0x1c4ef90>
53688 POLL_OK IOLoop.NONE
Test conn: <__main__.Connection object at 0x1c4ef90>
53689 POLL_OK IOLoop.NONE
Test conn: <__main__.Connection object at 0x1c4ef90>
53690 POLL_OK IOLoop.NONE
Test conn: <__main__.Connection object at 0x1c4ef90>
53691 POLL_OK IOLoop.NONE
Test conn: <__main__.Connection object at 0x1c4ef90>
53692 POLL_OK IOLoop.NONE
Test conn: <__main__.Connection object at 0x1c4ef90>
53693 POLL_OK IOLoop.NONE
Test conn: <__main__.Connection object at 0x1c4ef90>
53694 POLL_OK IOLoop.NONE
Test conn: <__main__.Connection object at 0x1c4ef90>
53695 POLL_OK IOLoop.NONE

Anyone knows how this fix this?

Ben Darnell

unread,
Oct 5, 2012, 11:54:25 PM10/5/12
to python-...@googlegroups.com
Maybe you need to call io_loop.remove_handler() when the state is
POLL_OK? The IOLoop always listens for at least ERROR events on all
registered fds (maybe we should just get rid of that NONE constant;
I'm not sure if it ever makes sense). If you really don't even care
about errors on the connection, removing the handler seems like the
right thing to do. If the connection was closed I think you'd
continually get ERROR events until you removed the handler.

-Ben

Frank Smit

unread,
Oct 6, 2012, 5:57:59 AM10/6/12
to python-...@googlegroups.com
I don't know what to say. i just had a type in the callback variable name...

https://gist.github.com/3839266
Reply all
Reply to author
Forward
0 new messages