pyRTOS is a real-time operating system (RTOS), written in Python. The primary goal of pyRTOS is to provide a pure Python RTOS that will work in CircuitPython. The secondary goal is to provide an educational tool for advanced CircuitPython users who want to learn to use an RTOS. pyRTOS should also work in MicroPython, and it can be used in standard Python as well.
pyRTOS was modeled after FreeRTOS, with some critical differences. The biggest difference is that it uses a voluntary task preemption model, where FreeRTOS generally enforces preemption through timer interrupts. This means there is a greater onus on the user to ensure that all tasks are well behaved. pyRTOS also uses different naming conventions, and tasks have built in message passing.
I’ve created a Real-Time Operating System in Python. It uses a voluntary preemption scheduler (though, if the MicroPython merge for CircuitPython 7 adds interrupt capability to CircuitPython, I’ll definitely be looking at adding a real-time preemption scheduler). Comprehensive documentation is available in the README on Github.
This actually works on desktop Python (where I developed it, for ease of testing), but I designed it specifically for use with CircuitPython devices. I’ve tested it successfully on a Rotary Trinkey (without the encoder, using one of the encoder pads as an additional touch input), and the test program I used is available on Github.
To the best of my knowledge, aside from voluntary preemption, the task scheduling is identical to that found in FreeRTOS. Tasks are assigned numerical priorities, the lower the number the higher the priority, and the highest priority ready task is given CPU time, where ties favor the currently running task. Alternative scheduling algorithms may be added in the future.
See more on the project GitHub page here.