【发布时间】:2016-03-16 10:19:37
【问题描述】:
我正在编写一个小程序,它有一个心跳进程和一个回显进程。我用一个多处理库实现了这个,但它似乎不起作用。
from multiprocessing import Process
import os
import time
def ticking():
while True:
time.sleep(1)
print 'ticking'
def echo():
while True:
a = raw_input('please type something')
print 'echo: ' + a
if __name__ == '__main__':
p = Process(target=ticking, args=())
p.start()
p.join()
p = Process(target=echo, args=())
p.start()
p.join()
【问题讨论】:
-
python-daemon 库是一个方便的包,可以轻松创建守护进程。
-
同意,
multiprocessing不是实现守护进程的正确工具。通常,您希望对 Unix 守护程序使用双分叉惯用语,因此只需使用 Carpetsmoker 链接的库即可。 -
@Carpetsmoker 谢谢,会试试 :)
标签: python multiprocessing daemon