A Command Queue for Python
Project description
A Command Queue for Python
Run commands (which can be regular functions) in a FIFO queue. Can be run in a background thread.
Usage examples
Simple filling and running of the queue
from command_queue import CommandQueue
from command_queue.commands import FunctionCommand
import functools
example_queue = CommandQueue()
# Add example commands
for i in range(100):
example_queue.add_command(
FunctionCommand(functools.partial(print, f"Running loop iteration {i}"))
)
# Attempt to run command queue at 60 commands per second
# Stop running once queue empties
example_queue.spin(60, until_empty=True)
Example of ParallelCommandGroups
from command_queue import CommandQueue
from command_queue.commands import FunctionCommand, ParallelCommandGroup
import functools
import time
def do_something():
print(f"Something happended on {time.time()}")
time.sleep(0.05)
def do_something_2():
print(f"Something_2 happended on {time.time()}")
time.sleep(0.05)
example_queue = CommandQueue()
# Add example non-parallel commands
# These commands will run sequentially
for i in range(2):
example_queue.add_command(FunctionCommand(functools.partial(do_something)))
# These commands will run at the same time using threads
# Add example parallel command
# These commands will run at the same time
example_queue.add_command(
ParallelCommandGroup(
FunctionCommand(functools.partial(do_something_2)),
FunctionCommand(functools.partial(do_something_2)),
FunctionCommand(functools.partial(do_something_2)),
FunctionCommand(functools.partial(do_something_2)),
FunctionCommand(functools.partial(do_something_2)),
FunctionCommand(functools.partial(do_something_2)),
)
)
# Attempt to run command queue at 10 commands per second
# Stop running once queue empties
example_queue.spin(10, until_empty=True)
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
command_queue-0.2.0.tar.gz
(16.5 kB
view hashes)
Built Distribution
Close
Hashes for command_queue-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb7e3ab177a0701dceca454f1a9f81d0fae2c8c3f7eb1170f4fd5f7ee68fea73 |
|
MD5 | f762da880deca78c961b1ac8f6194b40 |
|
BLAKE2b-256 | 51b9d45693d46723cb6d0e0bfdc75b0fb4cc75de69d36e45eecf692d0b4f7e55 |