Add Examples
This commit is contained in:
26
examples/process_pool.py
Normal file
26
examples/process_pool.py
Normal file
@ -0,0 +1,26 @@
|
||||
from falyx import Falyx, ProcessAction
|
||||
from falyx.themes.colors import NordColors as nc
|
||||
from rich.console import Console
|
||||
|
||||
console = Console()
|
||||
falyx = Falyx(title="🚀 Process Pool Demo")
|
||||
|
||||
def generate_primes(n):
|
||||
primes = []
|
||||
for num in range(2, n):
|
||||
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)
|
||||
return primes
|
||||
|
||||
# Will not block the event loop
|
||||
heavy_action = ProcessAction("Prime Generator", generate_primes, args=(100_000,))
|
||||
|
||||
falyx.add_command("R", "Generate Primes", heavy_action, spinner=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import asyncio
|
||||
|
||||
# Run the menu
|
||||
asyncio.run(falyx.run())
|
Reference in New Issue
Block a user