Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meowmeowahr/command_queue
FIFO Queue for Functions
https://github.com/meowmeowahr/command_queue
command command-queue fifo fifo-queue python queue
Last synced: 2 months ago
JSON representation
FIFO Queue for Functions
- Host: GitHub
- URL: https://github.com/meowmeowahr/command_queue
- Owner: meowmeowahr
- License: gpl-3.0
- Created: 2024-07-31T02:44:04.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-07-31T15:03:55.000Z (6 months ago)
- Last Synced: 2024-11-07T03:49:21.252Z (3 months ago)
- Topics: command, command-queue, fifo, fifo-queue, python, queue
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```python
from command_queue import CommandQueue
from command_queue.commands import FunctionCommand
import functoolsexample_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
```python
from command_queue import CommandQueue
from command_queue.commands import FunctionCommand, ParallelCommandGroup
import functools
import timedef 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)
```