[Tutor] Multi-threading help

Tino Dai tinoloc at gmail.com
Fri Sep 7 17:08:33 CEST 2007


Hi there,

      I'm working on a multi-threaded utility to monitor network connections
between three machines The configuration of the three machines are: a web
machine that feeds back to two machines for processing. Sometimes when the
web connection is closed, the corresponding processes on the two backend
machines don't close. How, I have the current set up is:

class web:
      def __init__(self):
            <set some stuff>

      def run(self,args):
             <loop to get some data>

class mach1:
      def __init__(self):
            <set some stuff>

      def run(self,args):
             <loop to get some data>

class mach2:
      def __init__(self):
            <set some stuff>

      def run(self,args):
             <loop to get some data>

class target:

     def run(self,args):
         ... collect data from web, mach1,
         mach2 classes, monitor connections,
        yada yada yada

My question is how to get the information to the target class. The target
class must have the web, mach1, mach2 data sets before doing any sort of
matching up of information. Now the ways that I have thought of are:
-Directing sending the information to the target object (there will only be
one)
-Using the Observer pattern to send the information from the web, mach1,
mach2 classes to the target object

And other question that I do have are:
-Is there a way to "block" run until I get information from the three other
objects. Presently, I can only think of looping and polling to see if the
information has come in yet. I'm sure there is a way because I have seen it
used in the SocketHandler class.
-Is there any way that I can be sure that two different objects are not
writing to target at the same time? The present way  that I'm thinking about
is using locking.

Thanks
Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070907/e244c4f5/attachment.htm 


More information about the Tutor mailing list