Asyncore select statement problem

JamesHoward James.w.Howard at
Fri Jan 19 18:42:04 CET 2007

Thank you for the responses.  I have learned considerably more about
how Asyncore works because of it.

The problem that I see is that Asyncore's poll function does not seem
to be thread safe.  From what I can tell, I am calling
dispatcher.close() properly and the dispatchers are removed from
asyncore's global map (all except the server itself).  However, it
seems like the error happens when the poll function gets the file
descriptors to run select on and then the thread ticks and removes them
from the global map.  After this the select call is made, but the file
descriptors are not valid anymore.

I guess I have two questions as a result.  First, is this a problem
that anyone else has had and second is there a fix for it?  I have
tried looking for Asyncore thread safe topics in Google, but without
much luck.  If needed I think making the poll function atomic in the
asyncore module might fix this problem, but I wanted to see what other
people thought first.

Thanks again for the help,
Jim Howard

Gabriel Genellina wrote:
> "JamesHoward" <James.w.Howard at> escribió en el mensaje
> news:1169075120.491855.103200 at
> >I have a problem with python's asyncore module throwing a bad file
> > descriptor error.  The code might be difficult to copy here, but the
> > problem is essentially:
> >
> > The server wants to sever the connection of an open Asyncore socket.
> > Calling the socket.close() nor the socket.shutdown(2) calls seem to
> > work.  The only way I can close the connection without creating the
> > error below is to have the client close the connection.
> You have to use the dispatcher's close() method, else, the asyncore map
> won't be updated, keeping a reference to the closed socket.
> -- 
> Gabriel Genellina

More information about the Python-list mailing list