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
schedule module, is there a micropython version
-
- Posts: 7
- Joined: Mon Apr 20, 2020 9:27 pm
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: sehedule module, is there a micropython version
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.
Index to my micropython libraries.
Re: sehedule module, is there a micropython version
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...
Though having an asyncio version of schedule would be very cool...
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: sehedule module: a uasyncio version?
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.
Index to my micropython libraries.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Schedule for uasyncio
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.
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.
Index to my micropython libraries.
Re: schedule module, is there a micropython version
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.
I will follow up with my thoughts after using this.
Again, Thank You very much.
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.
I will follow up with my thoughts after using this.
Again, Thank You very much.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
schedule module for micropython
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:
This runs bar with args 'hi' and 42 at 9am and 5pm so long as there isn't an 'r' in the month.
Code: Select all
asyncio.create_task(schedule(bar, 'hi', 42, month=range(5,9), hrs=(9,17)))
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.