Add ProcessPoolAction, update CAP to look only at keywords correctly
This commit is contained in:
@ -1,26 +1,36 @@
|
||||
from rich.console import Console
|
||||
|
||||
from falyx import Falyx
|
||||
from falyx.action import ProcessAction
|
||||
from falyx.action import ProcessPoolAction
|
||||
from falyx.action.process_pool_action import ProcessTask
|
||||
from falyx.execution_registry import ExecutionRegistry as er
|
||||
from falyx.themes import NordColors as nc
|
||||
|
||||
console = Console()
|
||||
falyx = Falyx(title="🚀 Process Pool Demo")
|
||||
|
||||
|
||||
def generate_primes(n):
|
||||
primes = []
|
||||
for num in range(2, n):
|
||||
def generate_primes(start: int = 2, end: int = 100_000) -> list[int]:
|
||||
primes: list[int] = []
|
||||
console.print(f"Generating primes from {start} to {end}...", style=nc.YELLOW)
|
||||
for num in range(start, end):
|
||||
if all(num % p != 0 for p in primes):
|
||||
primes.append(num)
|
||||
console.print(f"Generated {len(primes)} primes up to {n}.", style=nc.GREEN)
|
||||
console.print(
|
||||
f"Generated {len(primes)} primes from {start} to {end}.", style=nc.GREEN
|
||||
)
|
||||
return primes
|
||||
|
||||
|
||||
# Will not block the event loop
|
||||
heavy_action = ProcessAction("Prime Generator", generate_primes, args=(100_000,))
|
||||
actions = [ProcessTask(task=generate_primes)]
|
||||
|
||||
falyx.add_command("R", "Generate Primes", heavy_action, spinner=True)
|
||||
# Will not block the event loop
|
||||
heavy_action = ProcessPoolAction(
|
||||
name="Prime Generator",
|
||||
actions=actions,
|
||||
)
|
||||
|
||||
falyx.add_command("R", "Generate Primes", heavy_action)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user