motleycrew.crew.crew_threads
Thread pool module for running agents.
Classes
|
The thread class for running agents on task units. |
|
The thread pool class for running agents on task units. |
|
- class motleycrew.crew.crew_threads.TaskUnitThreadState(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum- BUSY = 'busy'
- WAITING = 'waiting'
- EXITED = 'exited'
- class motleycrew.crew.crew_threads.TaskUnitThread(input_queue: Queue, output_queue: Queue, *args, **kwargs)
Bases:
ThreadThe thread class for running agents on task units.
- __init__(input_queue: Queue, output_queue: Queue, *args, **kwargs)
Initialize the thread.
- Parameters:
input_queue – Queue of task units to complete.
output_queue – Queue of completed task units.
*args – threading.Thread arguments.
**kwargs – threading.Thread keyword arguments.
- property state
State of the thread.
- run() None
Main loop of the thread.
Gets a task unit from the input queue, runs it, and puts the result in the output queue. Exits when the sentinel object is retrieved from the input queue.
- class motleycrew.crew.crew_threads.TaskUnitThreadPool(num_threads: int = 4)
Bases:
objectThe thread pool class for running agents on task units.
- __init__(num_threads: int = 4)
Initialize the thread pool.
- Parameters:
num_threads – Number of threads to create.
- add_task_unit(agent: Runnable, task: Task, unit: TaskUnit) None
Adds a task unit to the queue for execution.
- Parameters:
agent – Agent to run the task unit.
task – Task to which the unit belongs.
unit – Task unit to run.
- get_completed_task_units() List[Tuple[Task, TaskUnit, Any]]
Returns a list of completed task units with their results.
- Returns:
List of triplets of (task, task unit, result).
- wait_and_close()
Wait for all task units to complete and close the threads.
- property is_completed: bool
Whether all task units have been completed.