我有三个过程。
主进程开始了BatchStreaming进程。
BatchStreaming进程启动了CameraProcess进程。
当主进程使用Ctrl + C键盘中断时,BatchStreaming进程和CameraProcess进程中的所有while循环都将停止。他们应该一个接一个地加入。现在不是。
可能是什么问题?
我的测试代码是
import multiprocessing as MultiProcess
def CameraProcess(stopbit):
while (not stopbit.is_set()):
test1=1
def BatchStreaming(stopbit):
camProcess = MultiProcess.Process(target=CameraProcess, args=(stopbit,))
camProcess.start()
while (not stopbit.is_set()):
test1=1
camProcess.join()
print('cam process join')
class ProcessPipeline:
def __init__(self):
#Current Cam
self.batchStreaming = None
self.stopbit = MultiProcess.Event()
def BatchProcessing(self):
self.batchStreaming = MultiProcess.Process(target=BatchStreaming, args=(self.stopbit,))
self.batchStreaming.start()
try:
while(self.stopbit is not None):
test=1
except KeyboardInterrupt:
print('Caught Keyboard interrupt')
except:
e = sys.exc_info()
print('Caught Main Exception')
print(e)
self.StopStreaming()
def StopStreaming(self):
print('in stopCamStream')
self.stopbit.set()
if not self.batchStreaming.is_alive():
self.batchStreaming.join()
print("batchProcess.join()")
print('All terminated')
if __name__ == "__main__":
mc = ProcessPipeline()
mc.BatchProcessing()