queue_processor Python3 Queue
Homepage: https://www.learningtopi.com/python-modules-applications/queue_processor/
This package is a simple threading based queue manager. A queue can be created with a specific maximum length as well as default command and final callback functions. When an item is added to the queue, the queue_processor will create a thread to execute the command function that was either provided when the item was added, or the default function for the queue. Arguments will be passed to the function and the return value will be captured. If a funal callback function is provided, the return value as well as the status will be returned along with a copy of the arguments.
The purpose of this class is to provide a modular and reusable queue that can be used in many different projects for any async tasks that need to be performed in sequence. The queue_processor operates as a FIFO queue and can provide a delay between tasks (i.e. for an IR transmitter where a pause is needed).
Use Example
from queue_processor import QueueManager, STATUS_OK, STATUS_TIMEOUT, STATUS_EXPIRED, STATUS_QUEUE_FULL, STATUS_EXCEPTION
def task(arg1, arg2):
print(f'executing task with {arg1}, {arg2}')
return arg1
def finished_callback(return_value, status, *args, **kwargs):
print(f'Completed task return value: {return_value}, status {status}, args: {args}, kwargs: {kwargs}')
queue = QueueManager(name='test1', command_func=task, callback_func=finished_callback)
queue.add(kwargs={'arg1': 1, 'arg2': 2})
Command Function
The command function can be any callable function (including a function that is part of a class). The function will be passed all the positional and keyword arguments that are supplied when adding the instance to the queue.
Callback Function
The callback function can be any callable function (including a function that is part of a class). This OPTIONAL function is called after the command function either completes or times out. The callback will provide the return value of the command function (if any) as well as a status that will be one of the following:
- OK: Command function completed (may or may not be successful in your view, but the function completed and did not raise any errors)
- TIMEOUT: If the command function did not complete within the timeout period.
- EXPIRED: The item was NOT executed as it sat in the queue longer than the max time permitted.
- QUEUE_FULL: This is returned if a callback is provided when an item is attempted to be added but the queue is full. This item is NOT executed.
- EXCEPTION: An exception was raised during the execution of the callback. The exception is returned as the "return_value"
Callback function parameters
The callback function must accept the "return_value" and "status" as positional arguments in that order. It is strongly recommended to include *args and **kwargs to catch all positional and keyword arguments that are sent after "return_value" and "status". The queue processor will send ALL arguments to the callback function that were also sent to the command function.
NOTE: You may send objects as parameters that will be updated by the command function! You may also have the command function be a member of a class instance. This allows you to act on data within an instance of a class so passing objects may not be required.
!!IMPORTANT!! The queue processor uses Python threads. In your command and callback function be sure to use thread locks appropriately if modifying data that may be accessed by a different thread. Also be sure not to create deadlocks!
Metadata
Release files for queue-processor 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| queue_processor-1.1.2.tar.gz | 8.7 kB | Without provenance | Details for queue_processor-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| queue_processor-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for queue_processor-1.1.2-py3-none-any.whl |
Total release size: 17.9 kB
Release files / queue_processor-1.1.2.tar.gz
| Download URL | queue_processor-1.1.2.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff391440d00523fd2c430d8c8219e3665ddaac81d3b6dc5649019565f8804329
|
|
BLAKE2b-256 checksum How to use checksums |
d6332adfd9f0c2b33f09d5e20cbf85f9e2091b8dcdacb14e57bf7f5df19bc0e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / queue_processor-1.1.2-py3-none-any.whl
| Download URL | queue_processor-1.1.2-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
10c800fc71be44bc7da8fea3ce29e1abbad44f4f89e23bf80d686383ed7fc608
|
|
BLAKE2b-256 checksum How to use checksums |
e8c18cf745a1e35b17f19dba9cb76bf8c442ce743ee3fae12aa71ad925dd7e31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for queue-processor 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.