2011-07-06 2 views
2

私はキュー(Redis Kombu)を聞くPython deamonを構築しようとしています。 このタスクを処理するには、タスクを取得し、greenthreadを起動します。イベントレットとPythonデーモン、Fooは呼び出されていませんか?

私はタスクを受け取り、問題なく使用することができますが、イベントレットを持つGreenThreadを生成しようとすると、何もしていないようです。

印刷されていないため、ログは表示されません。

class agent(Daemon): 
    """ 
    Agent 
    """ 
    def run(self): 
     # Setup connection 
     mainLogger.debug('Connecting to Redis') 
     connection = BrokerConnection(
         hostname=agentConfig['redis_host'], 
         transport="redis", 
         virtual_host=agentConfig['redis_db'], 
         port=int(agentConfig['redis_port'])) 
     connection.connect() 

     # Create an eventlet pool of size 5 
     pool = eventlet.GreenPool(5) 
     q = connection.SimpleQueue("myq") 
     while True: 
      try: 
       message = q.get(block=True, timeout=1) 
       print "GOT A MESSAGE FROM Q !" 
       pool.spawn_n(self.foo, 'x') 
       print "END SPAWN !" 
      except Empty: 
       mainLogger.debug('No tasks, going to sleep') 
       time.sleep(1) 


    def foo(self, x): 
     mainLogger.debug('\o/') 
     print "HELLO FROM SPAWN" 

私は間違っていますか?

答えて

3

sleep()呼び出しでコンテキスト切り替えを開始するためにeventlet.monkey_patch()を呼び出す必要がありました。ここで説明するように

関連する問題