Skip to main content

Concurrent job queue manager with multi-threading support

Project description

k3jobq

Build Status Python package 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 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


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.5.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k3jobq-0.1.5-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file k3jobq-0.1.5.tar.gz.

File metadata

  • Download URL: k3jobq-0.1.5.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3jobq-0.1.5.tar.gz
Algorithm Hash digest
SHA256 66e0028328f263e32b92e23e0371fce86c3c087646b59add6b77ec951ce0f611
MD5 ec40d586f4ef33885391c189982493fc
BLAKE2b-256 a96de3e9b6b405b0dd9f550c127cf640e5132c57a92eb3e69626ac78f2810fcd

See more details on using hashes here.

File details

Details for the file k3jobq-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: k3jobq-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3jobq-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a9b9edc0f6bf5bb61f688358fc6613b548660fa9ce6aa6e1065ac8f3b0ee87c0
MD5 ebf0536c5ff899ba5e5d1f2750070fae
BLAKE2b-256 24a04a2f59b2392de023dfb20f629b5d7e7cdcf02be0c6d12b83a97de56abcff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page