我有一个多处理用例,我想编写一个分派函数,它接收一个python函数和一个输入队列作为输入,然后通过多处理在该输入上分派该函数?
我不确定是否args
适合传入,因为该函数不会严格共享。
import multiprocessing
def dispatch(queue, function):
while True:
if queue.empty():
return
current_project = queue.get()
function(current_project)
def letter_rip(projects_filename, function):
project_file = open(projects_filename, 'r')
projects = project_file.readlines()
project_file.close()
q = multiprocessing.Queue()
for project in projects:
q.put(project)
for i in xrange(0, 128):
p = multiprocessing.Process(target=dispatch, args=(q, ???function??? ))
p.start()