Я пытаюсь построить Python deamon, который слушает очередь (Redis Kombu).Захватите задачу и создайте greenthread для ее обработки.
Я могу получить задачу и использовать ее без проблем, но когда я пытаюсь создать GreenThread с помощью eventlet, он, похоже, ничего не делает.
Нет печати, не отображается журнал.
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"
Что-то я не так делаю?