0

ありがとうございます。 マルチプロセッシングの新機能です。 私はRabbit MQueueのデータを同時に消費するプロセスを作成しましたが、一度に1つのプロセスしか実行しません。マルチプロセスウサギ消費者

def start_consum(queue_name): 
    channel.basic_consume(func, queue=queue_name) 
    channel.start_consuming() 

def process_start(number): 
    from multiprocessing import Process 
    events = ["ev1","ev2","ev3"] 
    for process in range(number): 
     for event in events: 
      proc = Process(target= start_consum(event)) 
      proc.daemon = True 
      proc.start() 


process_start(10) 

上記のコードでは、最初のイベントを消費してから2番目のイベントを開始します。

答えて

0

このスレッドを開始することができます。

class Threaded_worker(threading.Thread): 
    def __init__(self): 
     threading.Thread.__init__(self) 
     self.credentials = pika.PlainCredentials('', '') 
     self.connection = pika.BlockingConnection(pika.ConnectionParameters(credentials=self.credentials,host=)) 
     self.channel = self.connection.channel() 
     self.channel.basic_qos(prefetch_count=1) 
     events = ["ev1","ev2","ev3"] 
     for event in events: 
      self.channel.basic_consume(func, queue=event)    

    def run(self): 
     print 'start consuming' 
     self.channel.start_consuming() 

    def thread_start(numberofthreads):     
     for _ in range(numberofthreads): 
      td = Threaded_worker() 
      td.setDaemon(True) 
      td.start() 
+0

ありがとうございます@shashank – John

関連する問題