6
我有一个python类让我们称之为AClass和另一个扩展线程的MyThread。在这个AClass中,我创建了MyThread类的2个对象,并且我还有一个信号量,我将它作为MyThread类的构造函数的参数。我的问题是如果我在一个MyThread对象中修改信号量,另一个MyThread对象会看到差异吗?例如:Python线程和信号灯
class AClasss:
def function:
semafor = threading.Semaphore(value=maxconnections)
thread1 = Mythread(semafor)
thread2 = Mythread(semafor)
thread1.start()
thread1.join()
thread2.start()
thread2.join()
class MyThread(Thread):
def __init__(self,semaphore):
self.semaphore = semaphore
def run():
semaphore.acquire()
"Do something here"
semaphore.release()
那么thread1是否看到thread2所做的信号量更改,反之亦然?
非常感谢,我虽然如此,但在编码前我想确定一下。 – exilonX 2013-03-18 19:56:25