uasyncio - asyncio-like cooperative multitasking framework for uPy
Re: asyncio-like cooperative multitasking framework for uPy
Ok, asyncio branch was finally merged into micropython-lib master. This means it's little bit more mature than it was before . There're still changes to do to optimize it for running on pyboard, and to document it.
In the meantime, I started to write HTTP client for it: https://github.com/pfalcon/micropython-uaiohttpclient
In the meantime, I started to write HTTP client for it: https://github.com/pfalcon/micropython-uaiohttpclient
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: asyncio-like cooperative multitasking framework for uPy
uasyncio was split into 2 packages: uasyncio.core and uasyncio. uasyncio.core contains basic event loop implementation and should work on bare-metal targets like PyBoard. uasyncio adds POSIX (well, Linux) async I/O handling on top of that.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: asyncio-like cooperative multitasking framework for uPy
Last night, I made a short talk to present micropython to AFPY guys, and someone also presented asyncio.
At the end of the talk, we tried to use uasyncio to blink leds, but it failed. It seems that asyncio can't work on pyboard, because the ffi module is missing.
Am I right?
Is it possible to only use usayncio.core on pyboard to make a basic asyncio demo? How do I use it?
Thanks for your help.
At the end of the talk, we tried to use uasyncio to blink leds, but it failed. It seems that asyncio can't work on pyboard, because the ffi module is missing.
Am I right?
Is it possible to only use usayncio.core on pyboard to make a basic asyncio demo? How do I use it?
Thanks for your help.
Frédéric
Re: asyncio-like cooperative multitasking framework for uPy
Great!fma wrote:Last night, I made a short talk to present micropython to AFPY guys, and someone also presented asyncio.
Yes, as the previous message says, uasyncio.core was specifically split to let it being used on PyBoard. Full uasyncio module cannot be used on PyBoard, because it used Linux async i/o implementation (epoll). Surely, that will change with time.At the end of the talk, we tried to use uasyncio to blink leds, but it failed. It seems that asyncio can't work on pyboard, because the ffi module is missing.
Am I right?
Is it possible to only use usayncio.core on pyboard to make a basic asyncio demo?
I don't have a PyBoard with me, so don't to post unverified code, so here's code which will "blink" ON/OFF messages on your desktop monitor:How do I use it?
Thanks for your help.
Code: Select all
import logging
try:
import uasyncio.core as asyncio
except ImportError:
import asyncio
def loop():
while True:
print("ON")
yield from asyncio.sleep(1)
print("OFF")
yield from asyncio.sleep(1)
logging.basicConfig(level=logging.ERROR)
asyncio.get_event_loop().run_until_complete(loop())
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: asyncio-like cooperative multitasking framework for uPy
Ok, I wrote this little code:
It works fine if I use intergers as delays, but not if I use floats. Any idea why?
Code: Select all
import logging
import uasyncio.core as asyncio
import pyb
@asyncio.coroutine
def light(led, delayOn, delayOff):
"""
"""
while True:
print(repr(led))
led.on()
yield from asyncio.sleep(delayOn)
led.off()
yield from asyncio.sleep(delayOff)
def main():
"""
"""
logging.basicConfig(level=logging.ERROR)
loop = asyncio.get_event_loop()
leds = [pyb.LED(1), pyb.LED(2), pyb.LED(3), pyb.LED(4)]
#delays = [(1, 2), (1, 0.5), (0.5, 0.5), (0.25, 1)]
delays = [(1, 1), (1, 2), (2, 1), (2, 2)]
tasks = [asyncio.async(light(led, *delay)) for led, delay in zip(leds, delays)]
# loop.run_until_complete(asyncio.wait(tasks)) # not implemented
for task in tasks:
loop.call_soon(task)
loop.run_forever()
if __name__ == "__main__":
main()
Frédéric
Re: asyncio-like cooperative multitasking framework for uPy
If you look at the source, timing is handled via EventLoop.time(), which in turn uses time.time(). Whatever your platform's time.time() provides, that you have. Unix port provides fractional time values. STMHal port has only single-precision floats, so cannot represent both calendar time and subsecond precision in one value, so that's what you get. You can subclass EventLoop and override its time() to use whatever STMHal port provides of needed precision.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: asyncio-like cooperative multitasking framework for uPy
Is it possible to use pyb.millis()? Or will it stop working after 12.4 days?
Frédéric
Re: asyncio-like cooperative multitasking framework for uPy
There is a pyb.elapsedMillis() that takes rollovers into consideration.
http://docs.micropython.org/en/latest/l ... sed_millis
http://docs.micropython.org/en/latest/l ... sed_millis