Pipes, Sockets and Threads

rpevans at my-deja.com rpevans at my-deja.com
Tue Jul 18 05:27:03 EDT 2000


I have extended Python with some purpose built functions, written in C
which communicate with a server process, via named pipes.  Initially I
called one of these functions (mylib.fred ) from main to initiate
communications with the server. Once stablished I then started a thread,
again a mylib function, to monitor the pipe connection set up
previously.  This is does but locks out the rest of the system. Only
when the thread receives data from the server does the rest of the
system run momentarily before again hanging. My first line of attack was
to put the function which initiated the comms in a separate thread so
divorcing the comms from main completely (I hoped). Now I have the
problem of communicating data ( pipe/socket fds) from my first thread
back to main and then to the second thread which inplements the select .

This I have miserabley failed to do.

Firstly the python script gives me an attribute error on the join I
perform to wait for the first thread to finish. I have tried join(),
thread.join() , what should I put?

Secondly how do I transfer variables from the C extension library to and
from the Python module.  I asume I can't return a value from a thread in
the argument list. I have tried declaring a variable as global in python
and external in C without much (ie any succcess ).

Could anyone tell me how I can implement complete asynchronicity between
my mian module and the communication threads. Is there a site with some
example Python threaded code. The library reference is quite sparse in
this area. The books I have bought (O Reilly) do not mention threaded
architecture. Is there a book which covers this?

Many thanks

Richard Evans


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list