CoreB is a library for managing concurrent function execution and control in Python applications. This library includes capabilities for managing ThreadPoolExecutor, controlling processes with Controller, handling function outputs with Return, and executing tasks with Agent.
- Manage concurrent function execution using ThreadPoolExecutor
- Pause and resume function execution with Controller
- Handle function outputs with Return
- Manage and execute tasks in the processing core with Agent
- Optimized structure for executing tasks in a processing loop with Loop
Run the pip install -r requirements.txt
command and add the CoreB file to your project.
import time
from CoreB import Controller, Agent, Core
# Create a controller
controller = Controller(name="event")
def func(name, size=6, delay=1):
for i in range(size):
if controller.is_pause():
controller.wait_until_pause()
print(f"{i + 1} from {name}")
time.sleep(delay)
# Define tasks
tasks = [Agent(func, name="func1", size=10, _return_name="func1"), Agent(func, name="func2", _return_name="func2")]
core = Core(list_of_agents=tasks)
core.set_controller(controller)
core.run()
# Pause and resume execution
time.sleep(3)
core.pause("event")
core.add_task(Agent(func, name="func3 added", _return_name="func3"))
time.sleep(7)
core.resume("event")
A class for controlling function execution throughout the program.
pause()
: Pause executionresume()
: Resume function executionwait_until_pause(timeout)
: Wait until the controller resumes executionis_pause() -> bool
: Check the pause status
This class represents a function to be executed in CoreB.
- Takes a function, arguments, and a unique name for storing output as input.
The main class responsible for executing tasks.
run()
: Execute added functionspause(controller_name)
: Pause execution of functions associated with a specific controllerresume(controller_name)
: Resume execution of functionsadd_task(*agents)
: Add new tasks while running
Stores the outputs of executed functions in CoreB.
Manages task execution within a processing loop.
- Implementing advanced logging
- Implementing better methods for computing the number of Workers based on CPU conditions
- Add documentation for all classes and methods.
- Implement unit tests for core functionalities.
- Create examples demonstrating usage of the core.
- Optimize performance for large-scale tasks.
- Ensure compatibility with projects that have a main loop.
This project is released under the MIT license. Usage, modification, and distribution are permitted.
🚀 CoreB is a simple and powerful solution for managing concurrent processing in Python!