jobq.py -- Queue processing engine
jobq.py
processes serial of input elements with several functions
concurrently and sequentially.
Check out on github: jobq.
Example:
import jobq
def add1( args ):
return args + 1
def multi2( args ):
return args * 2
def printarg( args ):
print args
jobq.run( [ 0, 1, 2 ], [ add1, printarg ] )
# > 1
# > 2
# > 3
jobq.run( ( 0, 1, 2 ), [ add1, multi2, printarg ] )
# > 2
# > 4
# > 6
Specifing number of threads for each job:
# Job 'multi2' uses 1 thread.
# This is the same as the above example.
jobq.run( range( 3 ), [ add1, (multi2, 1), printarg ] )
# > 2
# > 4
# > 6
Multiple threads with order kept:
# keep_order=True to force to keep order even with concurrently running.
jobq.run( range( 3 ), [ add1, (multi2, 2), printarg ],
keep_order=True )
# > 2
# > 4
# > 6
Specifying total timeout:
# timeout=0.5 specifies that it runs at most 0.5 second.
jobq.run( range( 3 ), [ add1, (multi2, 2), printarg ],
timeout=0.5 )
Returning jobq.EmptyRst
prevents jobq
from delivering result to next job:
def drop_even_number( i ):
if i % 2 == 0:
return jobq.EmptyRst
else:
return i
jobq.run( range( 10 ), [ drop_even_number, printarg ] )
# > 1
# > 3
# > 5
# > 7
# > 9
Check out on github: jobq.
Archive
- 15 Nov 2020 slimarray: gzip的压缩率, 即时访问
- 28 Oct 2020 200行代码实现基于paxos的kv存储
- 18 Oct 2020 后分布式时代: 多数派读写的'少数派'实现
- 20 Dec 2019 Art of Pull Requests(翻译)
- 21 Nov 2019 掐指算算: 你的CDN多花了几百万?
- 19 Nov 2019 一年的素描练习
- 30 Oct 2019 互联网中对象访问频率的91分布
- 09 Jan 2019 哄好面试官系列-1: 比较2个python dict(多级)是否相同
- 04 Nov 2018 存储中的文件合并策略优化
- 27 Sep 2018 软件工程是个面包机
- 26 Aug 2018 程序员必须知道的事情, 一般人我不告诉他
- 16 Aug 2018 cgexec 无法继承 LD_PRELOAD 环境变量
- 04 Aug 2018 mysql group replication实践记录: 步骤, 问题和注意事项
- 13 Feb 2018 枚举所有整勾股数
- 03 Feb 2018 ansible中的include, include_tasks 和 import_tasks 的差别
- 20 Nov 2017 python 并发subprocess.Popen的坑
- 05 Aug 2017 程序员必读: 摸清hash表的脾性
- 06 May 2017 python 进程内存增长问题, 解决方法和工具
- 01 Feb 2017 xp的分布式系统系列教程之: Erasure-Code: 工作原理, 数学解释, 实践和分析.
- 01 Feb 2017 xp的分布式系统系列教程之: Erasure-Code: 工作原理, 数学解释, 实践和分析.
- 11 Nov 2015 可靠分布式系统基础 Paxos 的直观解释
- 28 Jul 2015 socket关闭: close()和shutdown()的差异
- 17 May 2015 随手改变世界之 git-auto-squash
- 17 Feb 2015 Numbers Programmers Should Know About Hash
- 11 Feb 2015 Vim-tabbar: Simple, stupid and fast tab-bar for VIM
- 24 Jul 2014 1% 慢请求优化
- 31 Jan 2014 Some useful resources
- 31 Jan 2014 jobq.py -- Queue processing engine