Я изменил пример очереди с производителем & потребителем этого Tornado documentation, но не похоже, что параметр timeout, переданный get(), работает вообще, так как потребитель не ждет 10 секунд до выброса исключения. В идеале производитель и потребитель будут работать одновременно. Кроме того, я не знаю, следует ли передать в параметре таймаута в секундах или миллисекундах:tornado асинхронная очередь не ждет
from tornado import gen
from tornado.ioloop import IOLoop
from tornado.queues import Queue
q = Queue()
@gen.coroutine
def consumer():
try:
while True:
item = yield q.get(timeout=10000)
try:
print('Doing work on %s' % item)
finally:
q.task_done()
except gen.TimeoutError:
print('timeout')
return
@gen.coroutine
def producer():
for item in range(5):
yield q.put(item)
print('Put %s' % item)
yield gen.sleep(2)
@gen.coroutine
def main():
# Start consumer without waiting (since it never finishes).
IOLoop.current().spawn_callback(consumer)
yield producer() # Wait for producer to put all tasks.
yield q.join() # Wait for consumer to finish all tasks.
print('Done')
IOLoop.current().run_sync(main)
и вот его исполнение:
Put 0
Doing work on 0
timeout
Put 1
Put 2
Put 3
Put 4