我试图创建一个简单的应用程序,持续监控收件箱,然后在对收到的邮件进行分类后,作为子进程调用各种功能。
我想让父进程继续它的while循环,而不等待子进程完成。
def main():
while 1:
checkForMail()
if mail:
if mail['type'] = 'Type1':
process1() #
spawn process1, as long as no other process1 process running,
however it's fine for a process2 to be currently running
elif mail['type'] = 'Type2':
process2()
spawn process2, as long as no other process2 process running,
however it's fine for a process1 to be currently running
# Wait a bit, then continue loop regardless of whether child processes have finished or not
time.sleep(10)
if __name__ == '__main__':
main()
如上所述,一个函数不应该有多于一个并发的子进程实例,然而,如果进程运行不同的函数,它们可以并发运行。
这是否可以用多处理包来做?