Why doesn't this asyncore.dispatcher.handle_read() get called?

Dun Peal dunpealer at gmail.com
Wed Apr 20 17:17:17 EDT 2011


On Apr 20, 3:01 pm, Jean-Paul Calderone <calderone.jeanp... at gmail.com>
wrote:
> You didn't let the program run long enough for the later events to
> happen.  loop(count=1) basically means one I/O event will be processed
> - in the case of your example, that's an accept().  Then asyncore is
> done and it never gets to your custom handle_read.

Wow, a response from a Twisted founder and core developer =)

You were right, of course. Incrementing the count to 2 on the
asyncore.loop() calls makes the snippet work as expected.

I'd definitely rather use Twisted. It's unclear why transmitting a
bytestream message between two servers should require low-level socket
incantations such as `self.create_socket(socket.AF_INET,
socket.SOCK_STREAM)` or `self.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR, 1)`. The stdlib should offer a higher-level
asynchronous communication abstraction to support such a
straightforward usecase. Twisted does provide that, but my humble
needs can't justify the extra dependency cost.

Thanks a lot, D.



More information about the Python-list mailing list