基于异步tornado-redis的可靠队列包

Torrelque的Python项目详细描述


https://bitbucket-badges.atlassian.io/badge/saaj/torrelque.svg?ref=defaulthttps://codecov.io/bitbucket/saaj/torrelque/branch/default/graph/badge.svghttps://badge.fury.io/py/Torrelque.png

托雷尔克

torrelque是一个python 3包,它提供了一个可靠的redis支持的队列并在其上运行 龙卷风IO回路。

不用再费劲,很容易说包是所描述队列的实现 在this blog post中 做了一些必要的改变和改进。

还有一个相关的同步队列包,名为saferedisqueue

安装

pip install Torrelque

使用

#!/usr/bin/env python3importrandomimportloggingimporttornadoredisfromtornadoimportgen,ioloopfromtorrelqueimportTorrelquelogger=logging.getLogger(__name__)@gen.coroutinedefproduce():redis=tornadoredis.Client()queue=Torrelque(redis,ioloop.IOLoop.current())whileTrue:for_inrange(5):task={'value':random.randint(0,99)}logger.debug('Produced task %s',task)yieldqueue.enqueue(task)yieldgen.sleep(10)@gen.coroutinedefprocess(task_data):logger.debug('Consmed task %s',task_data)yieldgen.sleep(1)@gen.coroutinedefconsume():redis=tornadoredis.Client()queue=Torrelque(redis,ioloop.IOLoop.current())whileTrue:task_id,task_data=yieldqueue.dequeue()ifnottask_id:continuetry:yieldprocess(task_data)yieldqueue.release(task_id)exceptException:logger.exception('Job processing has failed')yieldqueue.requeue(task_id,delay=30)@gen.coroutinedefmain():for_inrange(4):ioloop.IOLoop.current().spawn_callback(consume)yieldproduce()if__name__=='__main__':logging.basicConfig(level=logging.DEBUG,format='%(asctime)s%(message)s')ioloop.IOLoop.instance().run_sync(main)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何表示1。。Java中的n关系   java在安卓应用程序中添加polaris viewer   Java字符串::replaceAll仅替换第一个出现(可能不正确的正则表达式)   java Tomcat/JBoss部署后脚本   如何在Heroku Java应用程序中运行发出web请求的周期进程   java如何以纳秒为单位证明算法的时间   Solaris上的java自定义ListCellRenderer(使用jre5)   java试图为我的播放器类测试块实现播放器重力(RealtutsGml平台教程)   c#消耗一个。带有java的net web服务未显示预期结果   java在KOI8\R中检索html   基于java图形的搜索与基于随机的搜索   java如何检查安卓设备上的可用空间?在SD卡上?