MainThread blocks all others

Bryan Olson fakeaddress at nowhere.org
Wed Aug 10 10:02:02 EDT 2005


Nodir Gulyamov wrote:
 > Hi again, comments below:
 >
 >
 >>>    doSomeJob(self):
 >>>        ##### BLOCKING HERE ###
 >>>        if not self.myEvent.isSet():
 >>>            self.myEvent.wait()
 >>
 >>The initial 'if' is superflous.
 >
 > Excuse me, please explain.

The code:

     if some_event.isSet():
         some_event.wait()

does exactly the same thing as:

     some_event.wait()

See:

     http://docs.python.org/lib/event-objects.html


 >>>        self.myEvent.clear()
 >>>        # ... continue...
 >>>
 >>># this class subscribed to some observer which implements thread
 >>>class monitor:
 >>>    def __init__(self, klass):
 >>>        #do some init
 >>>        self.c = klass
 >>>    def update(self):
 >>>        self.c.increaseCounter()
 >>>
 >>>if __name__ == "__main__":
 >>>    cl1 = class1()
 >>>    m = monitor(cl1)
 >>>    mo = MonitorObserver(m)
 >>
 >>Obviously that won't work. You only have one thread, and it blocks
 >>in doSomeJob, so no one can ever trigger the even.
 >
 > Actually I have 2 threads. One of them is MainThread and second one is
 > created by Observer in which update method called.

Whatever other thread you have in other code, this code is
whacked. Who do you think calls cl1.increaseCounter(), and how
did they get a reference to cl1?


-- 
--Bryan



More information about the Python-list mailing list