[Python-Dev] threadsafe patch for asynchat (original) (raw)
Josiah Carlson jcarlson at uci.edu
Thu Feb 9 06:02:59 CET 2006
- Previous message: [Python-Dev] threadsafe patch for asynchat
- Next message: [Python-Dev] threadsafe patch for asynchat
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Mark Edgington <edgimar at lycos.com> wrote:
Martin v. Löwis wrote: > That patch looks wrong. What does it mean to "run in a thread"? > All code runs in a thread, all the time: sometime, that thread > is the main thread. > > Furthermore, I can't see any presumed thread-unsafety in asynchat. Ok, perhaps the notation could be improved, but the idea of the semaphore in the patch is "Does it run inside of a multithreaded environment, and could its push() functions be called from a different thread?"
Asyncore is not threadsafe. The reason it is not threadsafe is because there was no effort made to make it threadsafe, because it is not uncommon for the idea of asynchronous sockets to be the antithesis of threaded socket servers.
In any case, one must be very careful as (at least in older versions of Python on certain platforms), running sock.send(data) on two threads simultaneously for the same socket was a segfault. I understand that this is what you are trying to avoid, but have you considered just doing...
q = Queue.Queue() def push(sock, data): q.put((sock, data))
def mainloop(): ... while not q.empty(): sock, data = q.get() sock.push(data) ...
Wow, now we don't have to update the standard library to introduce a false sense of thread-safety into asyncore!
- Josiah
- Previous message: [Python-Dev] threadsafe patch for asynchat
- Next message: [Python-Dev] threadsafe patch for asynchat
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]