MainThread blocks all others
Nodir Gulyamov
gelios at rbcmail.ru
Wed Aug 10 07:35:22 EDT 2005
Tried to rewrite using Event() just as experiment, but unfortunately
MainThread will blocking all others.
Code below:
import threading
class class1:
def __init__(self):
self.myEvent = threading.Event()
result = doSomeJob()
def increaseCounter(self):
self.myEvent.set()
doSomeJob(self):
##### BLOCKING HERE ###
if not self.myEvent.isSet():
self.myEvent.wait()
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)
Observer realized as described in Thinking in Python, Bruce Eckel
http://mindview.net/Books/TIPython
Does anybody have any idea? Any help will be appreciated.
Thanks in advance to ALL!
Best regards,
/Gelios
"Nodir Gulyamov" <gelios at rbcmail.ru> wrote in message
news:42f9d4ef_2 at news.isis.de...
> Hi Bryan,
> Thanks for your reply.
> I tried to test your solution, but it doesn't work, hence
> threading.Semaphore object hasn't method to get value of semaphore.
> I looked to source code of semaphore.py and find out that value is private
> variable.
>
> Best regards,
> /Gelios
>
> "Bryan Olson" <fakeaddress at nowhere.org> wrote in message
> news:fRaKe.3656$zr1.2646 at newssvr13.news.prodigy.com...
>>I wrote:
>> > Make self.counter a semaphore. Untested code:
>>
>> A little clean-up. Still untested:
>>
>> import threading
>>
>> class class1:
>> def __init__(self):
>> self.counter = threading.semaphore(0)
>> result = self.doSomeJob()
>>
>> def increaseCounter(self):
>> self.counter.release()
>>
>> def doSomeJob(self):
>> # Busy-waiting sucks.
>> # while counter != 1:
>> # pass
>> self.counter.acquire()
>> # ... continue...
>>
>>
>> --
>> --Bryan
>
>
More information about the Python-list
mailing list