Gstreamer Python中图像批处理的并行处理

Gstreamer Python中图像批处理的并行处理,gstreamer,python-multiprocessing,python-multithreading,Gstreamer,Python Multiprocessing,Python Multithreading,我喜欢并行两个函数,一个用于图像批处理(流式处理所有25个图像),另一个用于处理批处理图像。它们需要并行 因此,我的主要功能是对图像进行批处理BatchStreaming(self),并对BatchProcessing(self,b_num)进行处理。现在BatchStreaming运行良好。流式传输25个图像后,需要继续进行批处理。我有两个并行进程。是的 (1) 在批流处理中循环时需要继续处理另一批图像 (2) 同时,需要处理当前的批处理图像 我不知道我应该使用进程还是线程。我更喜欢进程,因为

我喜欢并行两个函数,一个用于图像批处理(流式处理所有25个图像),另一个用于处理批处理图像。它们需要并行

因此,我的主要功能是对图像进行批处理
BatchStreaming(self)
,并对
BatchProcessing(self,b_num)
进行处理。现在BatchStreaming运行良好。流式传输25个图像后,需要继续进行批处理。我有两个并行进程。是的

(1)
在批流处理中循环时
需要继续处理另一批图像

(2) 同时,需要处理当前的批处理图像

我不知道我应该使用进程还是线程。我更喜欢进程,因为我喜欢利用CPU中的所有核心。(Python的线程仅在一个CPU核上运行)

那么我有两个问题 (1) 进程必须连接回主程序才能继续。但我需要继续下一批图片

(2) 在下面的程序中,当调用
BatchProcessing(self,b_num)
并将异常设置为

Caught Main Exception
(<class 'TypeError'>, TypeError("'module' object is not callable",), <traceback object at 0x7f98635dcfc8>)

我使用了如下所示的事件信号。 这对于我的应用程序来说更简单

当批处理循环有足够的图像时,信号进行批处理

#event_tut.py
import random, time
from threading import Event, Thread

event = Event()

def waiter(event, nloops):
    count=0
    while(count<10):
       print("%s. Waiting for the flag to be set." % (i+1))
       event.wait() # Blocks until the flag becomes true.
       print("Wait complete at:", time.ctime())
       event.clear() # Resets the flag.
       print('wait exit')
       count=count+1

def setter(event, nloops):
    for i in range(nloops):
       time.sleep(random.randrange(2, 5)) # Sleeps for some time.
       event.set()

threads = []
nloops = 10

threads.append(Thread(target=waiter, args=(event, nloops)))
threads[-1].start()
threads.append(Thread(target=setter, args=(event, nloops)))
threads[-1].start()

for thread in threads:
    thread.join()

print("All done.")
#事件_tut.py
导入随机、时间
从线程导入事件,线程
event=event()
def服务员(事件,nloops):
计数=0

而(countI使用事件信号,如下所示。 这对于我的应用程序来说更简单

当批处理循环有足够的图像时,信号进行批处理

#event_tut.py
import random, time
from threading import Event, Thread

event = Event()

def waiter(event, nloops):
    count=0
    while(count<10):
       print("%s. Waiting for the flag to be set." % (i+1))
       event.wait() # Blocks until the flag becomes true.
       print("Wait complete at:", time.ctime())
       event.clear() # Resets the flag.
       print('wait exit')
       count=count+1

def setter(event, nloops):
    for i in range(nloops):
       time.sleep(random.randrange(2, 5)) # Sleeps for some time.
       event.set()

threads = []
nloops = 10

threads.append(Thread(target=waiter, args=(event, nloops)))
threads[-1].start()
threads.append(Thread(target=setter, args=(event, nloops)))
threads[-1].start()

for thread in threads:
    thread.join()

print("All done.")
#事件_tut.py
导入随机、时间
从线程导入事件,线程
event=event()
def服务员(事件,nloops):
计数=0
而