python redis队列只排队1个工作

时间:2016-10-27 04:51:20

标签: python redis queue

一个超级简单的用例 - 使用redis队列放置图像下载作业

"<NSAutoresizingMaskLayoutConstraint:0x7fcc26abc8a0 h=-&- v=-&- _UIBackdropContentView:0x7fcc278c9890.width == _UIBackdropView:0x7fcc278c82b0.width>",
"<NSLayoutConstraint:0x7fcc26ca2ee0 H:|-(0)-[UIView:0x7fcc278c9520]   (Names: '|':_UIBackdropContentView:0x7fcc278c9890 )>",
"<NSLayoutConstraint:0x7fcc26ca2f30 H:[UIView:0x7fcc278c9520]-(0)-|   (Names: '|':_UIBackdropContentView:0x7fcc278c9890 )>",
"<NSLayoutConstraint:0x7fcc26ca2c20 H:|-(0)-[_UIBackdropView:0x7fcc278c82b0]   (Names: '|':UIView:0x7fcc278c8140 )>",
"<NSLayoutConstraint:0x7fcc26ca2c70 H:[_UIBackdropView:0x7fcc278c82b0]-(0)-|   (Names: '|':UIView:0x7fcc278c8140 )>",
"<NSLayoutConstraint:0x7fcc26ca28e0 H:|-(0)-[UIView:0x7fcc278c8140]   (Names: '|':AVAlphaUpdatingView:0x7fcc278c7b80 )>",
"<NSLayoutConstraint:0x7fcc26ca2930 H:[UIView:0x7fcc278c8140]-(0)-|   (Names: '|':AVAlphaUpdatingView:0x7fcc278c7b80 )>",
"<NSLayoutConstraint:0x7fcc26cd81f0 H:|-(14)-[AVButton:0x7fcc278ca160](LTR)   (Names: '|':UIView:0x7fcc278c9520 )>",
"<NSLayoutConstraint:0x7fcc26cd8a00 AVButton:0x7fcc26cca550.right == AVButton:0x7fcc26c05740.left - 10>",
"<NSLayoutConstraint:0x7fcc26cd8910 AVButton:0x7fcc26c05740.right == AVButton:0x7fcc26f83140.left - 10>",
"<NSLayoutConstraint:0x7fcc26cd8b70 AVButton:0x7fcc26f83140.right == UIView:0x7fcc278c9520.right - 14>",
"<NSLayoutConstraint:0x7fcc26cd8e70 H:[AVButton:0x7fcc278ca160]-(>=15)-[AVLoadingIndicatorView:0x7fcc26a91ad0](LTR)>",
"<NSLayoutConstraint:0x7fcc26cd8ec0 AVLoadingIndicatorView:0x7fcc26a91ad0.right <= AVButton:0x7fcc26cca550.left - 15>",
"<NSLayoutConstraint:0x7fcc26abe730 'UIView-Encapsulated-Layout-Width' H:[AVAlphaUpdatingView:0x7fcc278c7b80(0)]>"
 )

 Will attempt to recover by breaking constraint 
 <NSLayoutConstraint:0x7fcc26cd8e70 H:[AVButton:0x7fcc278ca160]-(>=15)-        [AVLoadingIndicatorView:0x7fcc26a91ad0](LTR)>

当我运行# main.py from redis import Redis from rq import Queue from tasks import download_asset queue = Queue(connection=Redis()) if __name__ == '__main__': image_urls = ['https://image.com/image1.png', 'https://image.com/image2.png'] job1 = queue.enqueue(download_asset, image_urls[0], result_ttl=5000) print job1 job2 = queue.enqueue(download_asset, image_urls[1], result_ttl=5000) print job2 import time; time.sleep(3) print job1.result print job2.result 时,

python main.py

结果没有,但我确实看到第二张图片已下载到文件夹中。 并在工人日志中

<Job 8de87fc3-0480-4181-bb57-182773eaa4dd: tasks.download_asset('https://image.com/image1.png')>
<Job 6e334cc7-e2a5-46cb-b28a-7f8df6921c44: tasks.download_asset('https://image.com/image2.png')>
None
None

只处理了1份工作

工人们正在使用01:48:26 default: tasks.download_asset('https://image.com/image2.png') (6e334cc7-e2a5-46cb-b28a-7f8df6921c44) download image 01:48:26 Job OK 01:48:26 Result is kept for 5000 seconds 01:48:26 01:48:26 *** Listening on default...

下载代码:

rq worker

我注意到的一件事是,如果我把睡眠时间(3)放入入队之间,那么第一次仍然没有入队

1 个答案:

答案 0 :(得分:0)

愚蠢的我,我有另一个来自同一个redis队列的工作的工人