python - 是否可以在 python 多处理中重新启动已经终止的进程?

标签 python python-multiprocessing

这是我的问题的示例代码:

import multiprocessing, time
def nopr():
        i=0
        while 1:
                i = i+1
                print i
                time.sleep(1)

p = multiprocessing.Process(target =  nopr)
print "process started"
p.start()
time.sleep(04)
print "process ended"
p.terminate()
time.sleep(1)


p.start()

最佳答案

不,你不能启动一个终止的进程,你必须重新创建它:

import multiprocessing, time
def nopr():
    i=0
    while 1:
        i = i+1
        print i
        time.sleep(1)

p = multiprocessing.Process(target =  nopr)
print "process started"
p.start()
time.sleep(04)
print "process ended"
p.terminate()
time.sleep(1)

p = multiprocessing.Process(target =  nopr) # recreate
p.start()

关于python - 是否可以在 python 多处理中重新启动已经终止的进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37462370/

相关文章:

python - 在 Flask-restplus 模型中不允许任何额外的字段

python - pandas 新列与系列对象列表不同

python - 具有多个参数和返回值的两个并行函数

python-3.x - 具有异步功能的 Python 多处理

python - 流程完成后如何更新切换按钮的状态?

Python 电子邮件模块 : form header "From" with some unicode name + email

python - PyPDF2 在打开不安全文件时是否采取任何安全措施?

python - pyinstaller:我的 cherrypy app exe 的 2 个实例被执行

python - 在 Python 中同时执行两个类方法

python - arcpy + 多处理 : error: could not save Raster dataset