k3jobq processes a series of inputs with functions concurrently
Project description
k3jobq
k3jobq processes a series of inputs with functions concurrently
k3jobq is a component of pykit3 project: a python3 toolkit set.
k3jobq is a manager to create cuncurrent tasks. It processes a series of inputs with functions concurrently and return once all threads are done::
def add1(args):
return args + 1
def printarg(args):
print(args)
k3jobq.run([0, 1, 2], [add1, printarg])
# > 1
# > 2
# > 3
Install
pip install k3jobq
Synopsis
#!/usr/bin/env python
import k3jobq
if __name__ == "__main__":
def add1(args):
return args + 1
def multi2(args):
return args * 2
def printarg(args):
print(args)
k3jobq.run([0, 1, 2], [add1, printarg])
# > 1
# > 2
# > 3
k3jobq.run((0, 1, 2), [add1, multi2, printarg])
# > 2
# > 4
# > 6
# Specify number of threads for each job:
# Job 'multi2' uses 1 thread.
# This is the same as the above example.
k3jobq.run(list(range(3)), [add1, (multi2, 1), printarg])
# > 2
# > 4
# > 6
# Create 2 threads for job 'multi2':
# As there are 2 thread dealing with multi2, output order will not be kept.
k3jobq.run(list(range(3)), [add1, (multi2, 2), printarg])
# Output could be:
# > 4
# > 2
# > 6
# Multiple threads with order kept:
# keep_order=True to force to keep order even with concurrently running.
k3jobq.run(list(range(3)), [add1, (multi2, 2), printarg],
keep_order=True)
# > 2
# > 4
# > 6
# timeout=0.5 specifies that it runs at most 0.5 second.
k3jobq.run(list(range(3)), [add1, (multi2, 2), printarg],
timeout=0.5)
# Returning *k3jobq.EmptyRst* stops delivering result to next job:
def drop_even_number(i):
if i % 2 == 0:
return k3jobq.EmptyRst
else:
return i
k3jobq.run(list(range(10)), [drop_even_number, printarg])
# > 1
# > 3
# > 5
# > 7
# > 9
Author
Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Copyright and License
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
k3jobq-0.1.2.tar.gz
(9.2 kB
view details)
Built Distribution
k3jobq-0.1.2-py3-none-any.whl
(11.1 kB
view details)
File details
Details for the file k3jobq-0.1.2.tar.gz
.
File metadata
- Download URL: k3jobq-0.1.2.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 102c0b36dfb05bb4253b6fcfe7e7b70353ede9df1ad9199d6db0a31fc462ef42 |
|
MD5 | 984eaa2602f59c3e46748fd35425842d |
|
BLAKE2b-256 | 1859a31dd77c0ed547d5b387ee788cccbaed662fdd3b1b4352add4fb639db221 |
File details
Details for the file k3jobq-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: k3jobq-0.1.2-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f151bad72e110c085d2d2b1f6fe9ef8fdfb76850344814ba12f653f89ebf173d |
|
MD5 | 211352e8d8eadb80c44f8b8387d6d9c7 |
|
BLAKE2b-256 | d643f380a5411e7ecdf13f56b76eeef20fa5a4ee26d0896057dfbe0b41e74d53 |