我正在为 OpenERP 创建一个模块,我必须在其中启动一个正在进行的过程。
OpenERP 在一个连续的循环中运行。当我单击一个按钮时,我的进程必须启动,并且它必须继续运行,而不会阻止 OpenERP 的执行。
为了简化它,我有这个代码:
#!/usr/bin/python
import multiprocessing
import time
def f(name):
while True:
try:
print 'hello', name
time.sleep(1)
except KeyboardInterrupt:
return
if __name__ == "__main__":
count = 0
while True:
count += 1
print "Pass %d" % count
pool = multiprocessing.Pool(1)
result = pool.apply_async(f, args=['bob'])
try:
result.get()
except KeyboardInterrupt:
#pass
print 'Interrupted'
time.sleep(1)
执行时,Pass 1
打印一次,然后打印无穷无尽的系列hello bob
直到CTRL+C
被按下。然后Pass 2
得到等等,如下图:
Pass 1
hello bob
hello bob
hello bob
^CInterrupted
Pass 2
hello bob
hello bob
hello bob
hello bob
我希望通行证与hello bob
's 保持平行增加。
我怎么做?