Skip to main content

Connor's Process Managerial (PM) is a utility that processes and enques functions.

Project description

Connor's Process Managerial (PM)

Connor's Process Managerial (PM) is a utility that processes and enques functions in a separate single thread. This is useful to handle multiple multiprocessed functions, and allows them all to run over a period of time without causing complex issues with multiprocessing.

To install: pip install process-managerial

Example code of usage:

from process_managerial import QueueSystem
import time
from pprint import pprint

# Sample function that succeeds by adding two numbers.
def task_success(x, y):
    time.sleep(2)
    return x + y

# Sample function that fails by raising an exception.
def task_failure():
    time.sleep(1)
    raise ValueError("Intentional error for demonstration.")

# Sample function that prints a message.
def task_print(message):
    time.sleep(1)
    print(message)
    return message

def main():
    # Instantiate the QueueSystem with a process directory and log file.
    qs = QueueSystem(process_dir="processes", log_path="queue_log.txt")
    
    # Start the background worker thread.
    qs.start_queuesystem()
    
    # Queue a task that will successfully complete.
    hex_success = qs.queue_function(task_success, 5, 10)
    print(f"Queued task_success with hex: {hex_success}")
    
    # Queue a task that is designed to fail.
    hex_failure = qs.queue_function(task_failure)
    print(f"Queued task_failure with hex: {hex_failure}")
    
    # Queue a task that prints a message.
    hex_print = qs.queue_function(task_print, "Hello, QueueSystem!")
    print(f"Queued task_print with hex: {hex_print}")
    
    # Wait individually for each task to finish.
    qs.wait_until_hex_finished(hex_success)
    qs.wait_until_hex_finished(hex_failure)
    qs.wait_until_hex_finished(hex_print)
    
    # Wait until the entire queue has been processed.
    qs.wait_until_finished()
    
    # Optionally, requeue the failed task for another attempt.
    print("Requeuing the failed task...")
    qs.requeue_hex(hex_failure)
    qs.wait_until_hex_finished(hex_failure)
    
    # Stop the background worker thread.
    qs.stop_queuesystem()
    
    # Retrieve and display final task statuses.
    print("\nFinal task statuses:")
    for hex_val in qs.get_hexes():
        props = qs.get_properties(hex_val)
        pprint({
            'hex': hex_val,
            'status': props.status.name,
            'result': props.result,
            'output': props.output,
            'start_time': props.start_time,
            'end_time': props.end_time
        })
    
    # Optional: Clear tasks older than a certain datetime.
    # Uncomment the following lines to remove pickle files for tasks with a start time before the cutoff.
    # import datetime
    # cutoff_time = datetime.datetime.now() - datetime.timedelta(seconds=5)
    # qs.clear_hexes(before_date=cutoff_time)
    # print("\nCleared tasks before:", cutoff_time)

if __name__ == "__main__":
    main()
.venv/bin/python -m build

.venv/bin/python3 -m twine upload --repository process_managerial dist/*

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

process_managerial-0.1.33.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

process_managerial-0.1.33-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file process_managerial-0.1.33.tar.gz.

File metadata

  • Download URL: process_managerial-0.1.33.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for process_managerial-0.1.33.tar.gz
Algorithm Hash digest
SHA256 29cb472ca0dafbf5e672a9e4baf38223f4f3f5b31f920d64015511efac5f96ae
MD5 88410a843a2b72d166f5e95194cbd249
BLAKE2b-256 552e96e3d81a18af17162d23226e4089ba66d1f0f2db8905c458c332a73e9085

See more details on using hashes here.

File details

Details for the file process_managerial-0.1.33-py3-none-any.whl.

File metadata

File hashes

Hashes for process_managerial-0.1.33-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d53e40e68222efdfa24d078d51d1f63ea7bccfe89aada8da09e65395d2db04
MD5 20c5b6dc6101b83d58413bdea751b350
BLAKE2b-256 7b8cc365c0894e6e6fcbf1b4bd5ce9d08bc21e311f1b795423ff16ab61e999d2

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