当真循环进行迭代时,我想发出一个信号,用整数、字典或字符串等数据更新等待它的Child.process
。在PyQt中
可以使用PyQt.Signal
对象来完成。Qt信号对象可以设置为字符串、dict或列表。使用signal.emit
方法可以“发出”一个可以被另一个对象“捕获”的变量。如何使函数process
在不使用PyQt信号对象的情况下与子对象和/或父对象交互
import time, multiprocessing
def process():
num = int()
while True:
print '...sleeping %s' % num
time.sleep(1)
num += 1
if num > 10:
break
return time.time()
class Child(object):
def __init__(self):
super(Child, self).__init__()
def process(self):
proc = multiprocessing.Process(target=process)
proc.start()
class Parent(object):
def __init__(self):
super(Parent, self).__init__()
child = Child()
time_completed = child.process()
print 'time_completed: %s' % time_completed
obj = Parent()
使用
multiprocessing.Queue
对象使process
函数与child
通信,然后与parent
对象通信:相关问题 更多 >
编程相关推荐