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
....
...
...
-- http://mail.python.org/mailman/listinfo/python-list