Asyncore Loop Question

John W jmw136 at gmail.com
Mon Oct 31 18:06:08 CET 2005


Hello,

I have a gui application where I am trying to use the asyncore module to
gather data from other computers. I am able to connect, but I am getting
constant handle_write_event method calls into my application. It is
obviously slowing down the gui processing significantly.

My understanding is that the handle_write_event and handle_read_event are
both edge notifications and I should just get the method call essentially
just once.

I think the problem is how I have my loop() call configured. All I am trying
to do with the code below is to open the socket (that works) and then
receive a single handle_write_event method call. Instead, I am getting
constantly barraged with them.

I have tried several different types of the loop() call (using poll,
timeout...) but with no luck. If anyone can explain what I should be doing
to get a single handle_write_event call until I actually write something to
the socket (which my code is not presently doing yet), I would appreciate

Below is some code showing what I am doing:

--------------------------------------------------------------
class Connection(asyncore.dispatcher):
def __init__ (self, server_name, port_num ):
self.message_queue = []

asyncore.dispatcher.__init__(self)
self.create_socket( socket.AF_INET, socket.SOCK_STREAM )
self.connect(( server_name, port_num ))


def handle_read_event( self ):
print "handle_read_event received"


def handle_write_event( self ):
print "Asking for a write"

if len( self.message_queue ) > 0:
# Pop the first message off the queue
self.send_next_message()


class TestApp:
def __init__( self, server_name, port_number ):

self.nomad = Connection( server_name, port_number )
asyncore.loop()


Output ends up being a constant stream of:
Asking for a write
Asking for a write
Asking for a write
Asking for a write
Asking for a write
....
...
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051031/390860b2/attachment.html>


More information about the Python-list mailing list