我正在编写一个简单的脚本来生成子进程并暂停和恢复子进程。为此,我正在存储子进程的pid,以便我可以暂停和恢复进程
例如:
os.kill(pid, signal.SIGSTOP) # for pause
os.kill(pid, signal.SIGCONT) # for resume
我的代码
class Multiprocessing:
def __init__(self):
self.pid = {}
def worker(self, idd):
pid = os.getpid()
self.pid[idd] = pid
# doing some thing
def start(self, a):
p = multiprocessing.Pool(processes=3)
print os.getpid()
l = []
for idd in a:
p.apply_async(self.worker, (idd,))
l.append(p)
obj = Multiprocessing()
obj.start()
print obj.pid # print empty dictionary i.e {}
请帮我解释如何在课堂对象上存储pid