need some help with threading module...

chahnaz.ourzikene chahnaz.ourzikene at wanadoo.fr
Sun Dec 26 23:12:18 CET 2004


I think it is more suitable in this form...



from threading import *

####################################

class Subject(object):


    def __init__(self) :

        self.counter = 0

        t = Timer(0.00001,self.doIteratingStuff)

        t.start()


    def incrementCounter(self,n=1) :

        self.counter = self.counter + n

    def doIteratingStuff(self) :

        for i in range(10) :

            self.incrementCounter(4)

            print "the counter is now", self.counter


    def count(self):

        return self.counter

####################################

class Controller(object):

    def __init__(self, objectToControl) :

        self.controlled = objectToControl

        self.th = Thread(target = self.stopCounting)

    def start(self):

        self.th.start()


    def stopCounting(self):

        i = 0

        #while(1):

        for i in range(100000) :

            print "###############################> waiting... ", i

            i = i + 1

            if self.controlled.count() >= 10 :

                print "it is ten"

                return

####################################

class Application (object) :

    def __init__(self) :

        pass

    def launch(self) :

        self.sub = Subject()

        self.control = Controller(self.sub)

        self.control.start()


####################################


a = Application()

a.launch()



Thanls for all.



Yacine Chaouche, France.





More information about the Python-list mailing list