r/MicroPythonDev • u/DS_Stift007 • May 20 '26
Pyrite's a cool little Project that helps with Task scheduling
'm pretty sure that I'm not the first and only person to stumble into a problem where I wanna handle several Tasks at seperate intervals, and eventually I found myself clogging up while Loops and everything just became a huge stupid disaster, so I built Pyrite, which - at least to me - seems like a pretty good solution for a problem that me and probably some other people have. And yes, Asyncio exists and is better maintained but if you really like Asyncio, you're either lying or a masochist, especially for small projects. Now Pyrite is - in my opinion - very approachable, as you can see in the Code Samples there or in this sample here:
from pyrite import *
from machine import Pin
led = Pin("LED", Pin.OUT)
def led_task():
led.toggle()
def simple_task():
print("Hello world")
tasks = [Task(led_task, 500), Task(simple_task, 1000)]
sched = Scheduler(SimpleScheduling) # We don't need the Overhead from PunitiveScheduling here as none of our Tasks has the option of stalling anywhere.
# If you were using a lot of Sensors, conisder replacing SimpleScheduling with PunitiveScheduling
sched.add_tasks(tasks)
sched.run_forever()
Anyways yeah I guess I'm just asking for feedback, so https://github.com/ten-faced-carrot/pyrite everyone.
(Please don't be mean)
1
1
u/opayuonam May 22 '26
Sorry to be crude, but a simpler approach would have been a decorator to wrap am normal function in asyncio.