Modify process_poll classmethod in the Bot class

Add process_poll function in a process_poll module
Modify documentation for process_poll
This commit is contained in:
Ichinga Samuel
2025-06-29 18:39:15 +01:00
parent 08ca91eda0
commit 8e0a551677
3 changed files with 23 additions and 7 deletions
+1
View File
@@ -2,3 +2,4 @@ from .core import *
from .lib import *
from .contrib import *
from ._utils import *
from .process_pool import process_pool
+6 -7
View File
@@ -21,7 +21,6 @@ class Bot:
config (Config): Config instance
mt (MetaTrader): MetaTrader instance
"""
config: Config
executor: Executor
mt: MetaTrader
@@ -34,17 +33,17 @@ class Bot:
self.strategies = []
@classmethod
def process_pool(cls, bots: dict[Callable:dict] = None, num_workers: int = None):
"""Run multiple bots in parallel using a ProcessPoolExecutor. Each bot should be a callable that accepts
def process_pool(cls, processes: dict[Callable:dict] = None, num_workers: int = None):
"""Run multiple processes in parallel using a ProcessPoolExecutor. Each bot should be a callable that accepts
keyword arguments only.
Args:
bots (dict): A dictionary of bots to run with their respective keyword arguments as a dictionary
num_workers (int): Number of workers to run the bots
processes (dict): A dictionary of processes to run with their respective keyword arguments as a dictionary
num_workers (int): Number of workers to run the processes
"""
num_workers = num_workers or len(bots) + 1
num_workers = num_workers or len(processes) + 1
with ProcessPoolExecutor(max_workers=num_workers) as executor:
for bot, kwargs in bots.items():
for bot, kwargs in processes.items():
executor.submit(bot, **kwargs)
async def initialize(self):
+16
View File
@@ -0,0 +1,16 @@
from typing import Callable
from concurrent.futures import ProcessPoolExecutor
def process_pool(processes: dict[Callable:dict] = None, num_workers: int = None):
"""Run multiple processes in parallel using a ProcessPoolExecutor. Each bot should be a callable that accepts
keyword arguments only.
Args:
processes (dict): A dictionary of processes to run with their respective keyword arguments as a dictionary
num_workers (int): Number of workers to run the processes
"""
num_workers = num_workers or len(processes) + 1
with ProcessPoolExecutor(max_workers=num_workers) as executor:
for bot, kwargs in processes.items():
executor.submit(bot, **kwargs)