Skip to main content

Priority queue with task categorisation support

Project description

Priority queue with task categorisation support

Current build status Latest PyPI version

Overview

taskq is a heap based priority queue that adds support to partition tasks into categories for selective removal.

The main driver for the project was work/task queueing where jobs need to be distributed to workers with different capabilities and non-uniform processing times (for calculating efficient prefetch).

This library is not thread-safe and is not intended as a replacement for python’s queue.Queue class.

Getting Started

Install using pip:

pip install taskq

Basic FIFO usage:

>>> from taskq import Queue
>>> q = Queue()
>>> q.push('task1')
>>> q.push('task2')
>>> q.pop()
'task1'
>>> q.pop()
'task2'

Task priorities (complex types that define __cmp__ are also supported):

>>> from taskq import Queue
>>> q = Queue()
>>> q.push('task1', 2)
>>> q.push('task2', 1)
>>> q.pop()
'task2'
>>> q.pop()
'task1'

Multi-pop:

>>> from taskq import Queue
>>> q = Queue()
>>> q.push('task1')
>>> q.push('task2')
>>> q.push('task3')
>>> q.pop(2)
['task1', 'task2']

Task categories:

>>> from taskq import Queue
>>> q = Queue()
>>> q.push('task1', category='foo')
>>> q.push('task2', category='bar')
>>> q.push('task3', category='foo')
>>> q.pop(2, categories=['dog', 'foo'])
['task1', 'task2']

Category ratios:

>>> from taskq import Queue
>>> q = Queue()
>>> q.push('task1', category='foo')
>>> q.push('task2', category='bar')
>>> q.push('task3', category='foo')
>>> q.pop(2, categories=['bar', 'foo'], ratios=[1, 0.5])
['task1', 'task2', 'task3']

The above example is useful when prefetching/distributing tasks that have non-uniform processing durations. If the category ratios represent average duration in seconds, the count can be used to pull approximately count seconds worth of the higest priority tasks from the queue.

See source documentation for other feature examples.

Issues

Source code for taskq is hosted on GitHub. Any bug reports or feature requests can be made using GitHub’s issues system.

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

taskq-0.3.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

taskq-0.3-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file taskq-0.3.tar.gz.

File metadata

  • Download URL: taskq-0.3.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for taskq-0.3.tar.gz
Algorithm Hash digest
SHA256 24ce799f0359d2d7081b12fcdab31adf3b5cda2886ba9000f9c09f627541c16f
MD5 97c0cf2873b149d3effc83a98d94b944
BLAKE2b-256 83416b4bb212e1fd91ff114057056dc0e8b58fb0972293ccf5442b6767829059

See more details on using hashes here.

File details

Details for the file taskq-0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for taskq-0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bc8c7b5f5ea17127d93dae804acd0ddd036e6505c0e28a936b0dbd73484fe9c3
MD5 02e00fc41e05012f1fd34ad4c872ea9d
BLAKE2b-256 c3fb47c7cf62789ec3fcd90d462f5b8691fe448586eebe40bcb202fd0098850a

See more details on using hashes here.

Supported by

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