@
nightwitch 感谢链接,应该就是我要找的帮助,谢谢!
@
ClericPy 感谢告知可以根据 debugging-port 的方式 kill chrome
试着写了个模拟的程序,进程是被停下来了,但是这个进程池好像再也用不料了。。。
```
# coding=utf-8
import codecs
import difflib
import os.path
import re
import time
import string
import chardet
import shutil
import copy
from concurrent.futures import ProcessPoolExecutor
import datetime
def PrintCount(PName):
if PName == '甲':
DelayTime = 0.9
if PName == '乙':
DelayTime = 1.2
if PName == '丙':
DelayTime = 1.7
if PName == '丁':
DelayTime = 2
if PName == '戊':
DelayTime = 2.5
countt = 0
while True:
countt += 1
time.sleep(DelayTime)
print(f'{PName}池:->',f'{countt}')
if __name__ == '__main__':
StartTime = time.clock()
FutureDict = {}
FutureRetDict = {}
FutureTimeRecoderDict = {}
PoolNameList = ["甲", "乙", "丙", "丁", "戊"]
# 初始化进程池
for i in range(len(PoolNameList)):
# 进程
FutureDict.update({PoolNameList[i]: ProcessPoolExecutor(max_workers=1)})
# 进程 Ret
FutureRetDict.update({PoolNameList[i]: futures.Future()})
# 进程启动时间
FutureTimeRecoderDict.update({PoolNameList[i]: None})
# 模拟测试清空进程池的信号
closeflag = True
# 开始工作
while True:
ProcessNum = 0
# 增加任务
for ProcessName,FutureRet in FutureRetDict.items():
# 模拟 40 秒后终结 [乙] 进程池
if closeflag == True:
if time.clock() - StartTime >= 40: # 在启动 40 秒后触发
print(f"开始强制结束 [乙] 进程池")
for pid, process in FutureDict['乙']._processes.items():
process.terminate()
FutureDict['乙'].shutdown()
closeflag = False
time.sleep(15)
# 如果进程池在运行
if FutureRet.running() == True:
pass
else:
# 增加任务
FutureRetDict[ProcessName] = FutureDict[ProcessName].submit(PrintCount,ProcessName)
print(f'{ProcessName} 进程池提交了开始.')
time.sleep(2)
break
time.sleep(3)
```
40 秒之后,乙进程池的确被停了,但是再向乙进程池提交任务的时候,会提示:
```
甲池:-> 57
甲池:-> 58
丙池:-> 25
戊池:-> 13
甲池:-> 59
丁池:-> 19
甲池:-> 60
丙池:-> 26
Traceback (most recent call last):
File "D:/
TestForMu.py", line 80, in <module>
FutureRetDict[ProcessName] = FutureDict[ProcessName].submit(PrintCount,ProcessName)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\
process.py", line 452, in submit
raise BrokenProcessPool('A child process terminated '
concurrent.futures.process.BrokenProcessPool: A child process terminated abruptly, the process pool is not usable anymore
甲池:-> 61
戊池:-> 14
丁池:-> 20
丙池:-> 27
```
应该要做些什么事情,再次启用?
原谅我这样设计流程,也许不是科学的,只是尽早希望能跑起多进程,把问题解决了就好。。。^_^
谢谢大家解答!