Embedded Threading Question

hg hansgeunsmeyer at earthlink.net
Sat Dec 7 14:54:25 EST 2002


tpdietz at hotmail.com (Tim Dietz) wrote in message 

> However, my problem occurs whether or not I
> process the data read from the socket, so I've eliminated that code. 
> In addition, the server can send asynchronous updates to this client,
> which are also processed in the ReadThread.
> 
> So, below is the streamlined version of my Python module (client.py):
> 
> def SendMsg(outmsg):
>    mysock.send(outmsg)
> 
> def ReadThread():
>    done = 0
>    buf = ''
>    while not done:
>       rcv,wr,err = select.select([mysock],[],[],0.1)
>       if mysock in rcv:
>          buf += rcv[0].recv(1000)
> 
> If I run Python from a DOS prompt, import this file and connect to the
> server, the server can send me as many asynchronous updates as it
> wants and the ReadThread handles them without a problem.  Fast and
> efficient.

When I import this (plus a few lines to set up the socket), it does
not
work when ReadThread is running in a separate thread.
If those two functions run in separate threads, you might get into
problems when you call mysock.recv and mysock.send
(quasi-)simultaneously. (But I doubt that that's the cause of your
current problems.)

> So, any ideas as to why the ReadThread acts so strangely in the C
> application?

Unfortunately, no.

Hans



More information about the Python-list mailing list