Skip to main content

k3jobq

Action-CI Documentation Status Package

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 concurrent 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

Metadata

Release files for k3jobq 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3jobq 0.1.9
File Size Uploaded
k3jobq-0.1.9.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for k3jobq 0.1.9
File Interpreter ABI Platform
k3jobq-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release files / k3jobq-0.1.9.tar.gz

Download URL k3jobq-0.1.9.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
99f0c67b3f76bd0c891dd37e793f250e5da26106dd8a48fc4ed37100aa7be201
BLAKE2b-256 checksum
How to use checksums
c6f51ad7b602362a32f7387c2726c935bd3862c096d8bc48111d92c4b59a71ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3jobq-0.1.9-py3-none-any.whl

Download URL k3jobq-0.1.9-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eeac9d6067a7e66178a12abb8b13ac79e753ef197062d306815bf2b60818204a
BLAKE2b-256 checksum
How to use checksums
3fdac51ab1d4ce6d3d10d28602f677f84409a868a163ca231aec1ed57b5ec14b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

0.1.10

2 release files

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page