Skip to main content

mhddq

Module implementing a multi-threaded hdd io queue.

pip install mhddq

codefactor circleci codecov

import mhddq
import time

# calls are enqueued instead of being called immediately
# 2 alternating io threads handle all io functions
# ideally while one thread is dealing with queue maintenance the
# other thread is using the hdd, and then they trade off when done
# after a function has been completed by the io threads its output
# is enqueued for a third thread to handle the callback as to not
# interfere with the two io threads
mhddq.file_exists(callback = cb_file_exists, filename = './file.txt')

def cb_file_exists(args):
    # args = {
    #     'action': str,  # function name, 'file_exists' in this case
    #     'result': bool, # if the function encoutered any errors then this is False
    #     'params': dict, # the params you initially passed, { 'callback': function, 'filename': str }
    #     'output': dict  # the output of the function, in this case { 'exists': bool }
    #                     # if result is False then this would be { 'exception': str }
    # }
    
    # print the result, 'file.txt exists: False'
    print(args['params']['filename'] + ' exists: ' + str(args['output']['exists']))
    
    # if a callback throws an exception it is caught and printed to stderr

# if multiple operations need to be grouped together you can use an oplist
fileops = mhddq.create_empty_oplist()

# oplists have their own sets of function calls
# in practice it ends up being the same as mhddq.file_exists()
# except the io thread considers the entire oplist as a single
# operation and won't yield to it's sister thread until the list
# has been completed
mhddq.oplist_file_exists(oplist = fileops, callback = cb_file_exists, filename = './file.txt')

# you can add an oplist directly to the io queue like this
mhddq.enqueue_oplist(fileops)

# or you can embed the oplist in another oplist
superlist = mhddq.create_empty_oplist()
mhddq.embed_oplist(superlist, fileops)

# embedded lists are processed as a single operation inside it's
# parent list, while it's parent list is processed as a single operation
# in the io queue
mhddq.enqueue_oplist(superlist)

# when it is time to turn off the app you can do a graceful shutdown
# this will prevent any new items from being enqueued and blocks the
# calling thread until the io and callback threads have cleared their
# queues and exited their processing loops
mhddq.shutdown()

# other threads can wait for a graceful shutdown by using a loop like this
while mhddq.is_shutdown() is False:
    time.sleep(0.01)

# once shutdown, mhddq can not be restarted without restarting the app

Metadata

Release files for mhddq 0.3.0

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

Source distribution (sdist)

Source distribution for mhddq 0.3.0
File Size Uploaded Provenance Actions
mhddq-0.3.0.tar.gz 14.4 kB Without provenance Details for mhddq-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mhddq 0.3.0
File Interpreter ABI Platform Actions
mhddq-0.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for mhddq-0.3.0-py2.py3-none-any.whl

Total release size: 28.2 kB

Release files / mhddq-0.3.0.tar.gz

Download URL mhddq-0.3.0.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
db2431576bd87fd34f2a47aea6dda26d0d4ab11698830892411e5812c76990ff
BLAKE2b-256 checksum
How to use checksums
4eccb079dc6e42a4dfbe8d4f8a1f2bd8f43bee021e2e01e330291d3e0369dd88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / mhddq-0.3.0-py2.py3-none-any.whl

Download URL mhddq-0.3.0-py2.py3-none-any.whl
Size 13.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f0cc9e526ce98934cc16e14201db68733963c687f324a232acfa1cbab402efa5
BLAKE2b-256 checksum
How to use checksums
86a165878d5f540b9445ff4a00406ad77eb17f2f47a86b8d5bba771b0fd7c2a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Security for mhddq 0.3.0

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.

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