question on multithreading, pipes

Jean-Yves Nief j-y.nief at wanadoo.fr
Mon Dec 15 22:09:26 CET 2003


hello,

          I have written a script which is performing some tasks in
multithreading mode: the main thread is opening a connection to a
distant server and all the threads that I start will have to perform
actions on the remote server using the connection initiated by the main
thread. At first sight, the only way I could achieve that in a proper
manner (ie without having to open a connection to the remote server in
every single thread and close it at the end of the thread) would be to
use a pipe that I would use in all the threads, for example:
* main thread:
fw, fr = os.popen2('/bin/ksh')
fw.write('Sinit')
etc...
* other threads:
fw.write('perform action')
etc...

but if I do that, I need to queue the events, which means I have to
serialize the jobs perform by the threads, which is clearly not what I
want as I am using threads :-)
so my question is: how could I get around this without giving up
multithreading ?
any help appreciated.
thanks,
JY








More information about the Python-list mailing list