schedule module, is there a micropython version

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
outsidewall
Posts: 7
Joined: Mon Apr 20, 2020 9:27 pm

schedule module, is there a micropython version

Post by outsidewall » Sat Jul 04, 2020 9:57 am

Hello,

I have found a very useful module called schedule for 'big' python (https://pypi.org/project/schedule/)
I have also found a micropython-schedule (https://pypi.org/project/micropython-schedule/)

The modules functionality will fit my needs perfectly....

Sadly the micropython-schedule, needs logger and functools, I'm not bothered by logger, easy removal,
but functools... not sure there is a version suitable.

Just a low down on what I want to do...
Setup a number of scheduled events, timing does not need to be very accurate.
The scheduler 'run' function must not be blocking, i.e. check if a job needs running.

Does any one have any ideas... we like simple.

Regards John

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: sehedule module, is there a micropython version

Post by pythoncoder » Sun Jul 05, 2020 8:17 am

I would look at uasyncio which is the MicroPython version of CPython's asyncio. There is a tutorial here.
Peter Hinch
Index to my micropython libraries.

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: sehedule module, is there a micropython version

Post by mattyt » Sun Jul 05, 2020 11:25 am

Lightweight implementations of both logger (well, logging) and functools can be found in micropython-lib. They may be enough?

Though having an asyncio version of schedule would be very cool... ;)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: sehedule module: a uasyncio version?

Post by pythoncoder » Mon Jul 06, 2020 5:37 am

mattyt wrote:
Sun Jul 05, 2020 11:25 am
...
Though having an asyncio version of schedule would be very cool... ;)
That is an interesting idea. The library is clearly excellent for its intended application: cron-like scheduling on a PC. The question is how suitable it is for firmware use, and whether it might be adapted.

The schedule team describe it as lightweight - fair point on a PC, but perhaps not on an ESP8266. It makes heavy use of inefficient properties. It doesn't support concurrency, and (so far as I can see) doesn't do anything which can't readily be done with uasyncio.

But a subset based on uasyncio and designed for firmware use might flatten the uasyncio learning curve and simplify some applications. You might even have schedule.when(callback, args).do(job) which polled some external event.

Its ingenious user friendly syntax does depend on properties, so there is a dilemma for any implementer. Food for thought.
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Schedule for uasyncio

Post by pythoncoder » Wed Jul 15, 2020 9:38 am

OK, I couldn't resist the challenge. here is my attempt. It aims to comply with MicroPython efficiency guidelines, so doesn't use properties. Consequently its syntax is different.

I think my syntax is reasonable for Python programmers. To specify multiple times or dates it uses the iterator protocol. This means you can use lists, sets, tuples or ranges to specify multiple values for any time or date argument. Functionality is a subset of schedule in a fast lightweight script. It is cross-platform, but the issue of DST needs to be considered on the Unix build.

My primary interest is in uasyncio scheduling, but for uasyncio phobics there is also a demo of using the code in synchronous code.
Peter Hinch
Index to my micropython libraries.

kinno
Posts: 32
Joined: Mon Oct 21, 2019 2:06 pm

Re: schedule module, is there a micropython version

Post by kinno » Wed Jul 15, 2020 11:09 am

Peter,

This looks very well done. I love your documentation style and thoroughness. I will be able to use this for a couple of my projects and when I get around to implementing it I will definitely leave some feedback.

But first, I wanted to say thanks for putting it together. Your contributions are greatly appreciated. :D

I will follow up with my thoughts after using this.

Again, Thank You very much.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

schedule module for micropython

Post by pythoncoder » Mon Jul 20, 2020 9:08 am

I have updated this to simplify its use with uasyncio. There is no need to learn about cron objects as you can schedule tasks with this syntax:

Code: Select all

asyncio.create_task(schedule(bar, 'hi', 42, month=range(5,9), hrs=(9,17)))
This runs bar with args 'hi' and 42 at 9am and 5pm so long as there isn't an 'r' in the month.
Peter Hinch
Index to my micropython libraries.

Post Reply