如何为 python 中的每个进程使用列表的不同值
How to use distinct value of a list for a each process in python
我有一个列表,例如
foo = ['battery', 'correct', 'horse', 'staple']
现在我正在使用多处理,并且我在每个进程中使用列表中的一个值。现在我希望我的进程不要使用已经被另一个进程使用的值。如果列表中有 4 个值,那么最多会有 4 个进程。我怎样才能做到这一点。
我正在添加一些代码行。希望你能觉得它有用。
def your_function(name):
print('hello', name)
from multiprocessing import Process` #import multiprocessing
foo = ['battery', 'correct', 'horse', 'staple']# your lis
processVar = ['t1','t2','t3','t4'] # You can create dynamic variable as per your need
for var,fooItems in zip(processVar,foo):
var = Process(target=your_function, args=(fooItems,))
var.start()
我有一个列表,例如
foo = ['battery', 'correct', 'horse', 'staple']
现在我正在使用多处理,并且我在每个进程中使用列表中的一个值。现在我希望我的进程不要使用已经被另一个进程使用的值。如果列表中有 4 个值,那么最多会有 4 个进程。我怎样才能做到这一点。
我正在添加一些代码行。希望你能觉得它有用。
def your_function(name):
print('hello', name)
from multiprocessing import Process` #import multiprocessing
foo = ['battery', 'correct', 'horse', 'staple']# your lis
processVar = ['t1','t2','t3','t4'] # You can create dynamic variable as per your need
for var,fooItems in zip(processVar,foo):
var = Process(target=your_function, args=(fooItems,))
var.start()