我有一个多进程设置,或多或少看起来如下:
import multiprocessing
class Worker(multiprocessing.Process):
def __init__(self, name):
self.name = name
def run(self):
while True:
#do something
print( self.name + " is working!")
#wait a few seconds
def main():
workers = []
for a in ["A", "B", "C", "D"]:
w = Worker(a)
workers += [w]
w.start()
我想做的是能够从 main() 更改工作人员的名称。为每个工人创建一个单独的队列是这样做的唯一方法,还是有更好的方法?我觉得我通过使用多进程不断遇到限制,我不确定我被允许做什么了。