Page 1 of 1

schedule module, is there a micropython version

Posted: Sat Jul 04, 2020 9:57 am
by outsidewall
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

Re: sehedule module, is there a micropython version

Posted: Sun Jul 05, 2020 8:17 am
by pythoncoder
I would look at uasyncio which is the MicroPython version of CPython's asyncio. There is a tutorial here.

Re: sehedule module, is there a micropython version

Posted: Sun Jul 05, 2020 11:25 am
by mattyt
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... ;)

Re: sehedule module: a uasyncio version?

Posted: Mon Jul 06, 2020 5:37 am
by pythoncoder
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.

Schedule for uasyncio

Posted: Wed Jul 15, 2020 9:38 am
by pythoncoder
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.

Re: schedule module, is there a micropython version

Posted: Wed Jul 15, 2020 11:09 am
by kinno
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.

schedule module for micropython

Posted: Mon Jul 20, 2020 9:08 am
by pythoncoder
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.