【发布时间】:2021-05-01 08:16:09
【问题描述】:
我正在尝试创建一个简单的应用程序,它会持续监控收件箱,然后在对传入邮件进行分类后,将各种函数作为子进程调用。
我希望父进程在不等待子进程完成的情况下继续它的 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()
如上所述,一个函数的并发子进程实例不应超过一次,但是如果进程运行不同的函数,它们可以同时运行。
这可能与多处理包有关吗?
【问题讨论】: