Running webserver and other code simultaneously
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Running webserver and other code simultaneously
You can indeed precompile code with mpy-cross and copy the .mpy file into your filesystem. This works fine but is something I seldom use because all it saves on the target is the compilation phase. It doesn't save RAM at runtime. Its main use is where you have a module which is too large to compile on the target but not too large to run without freezing. I've used it then because the turn-round time is much faster than the compile-link-flash cycle for frozen bytecode.
It can also save time if you have a module you want to run as soon as possible after boot, but this is rather a niche situation.
It can also save time if you have a module you want to run as soon as possible after boot, but this is rather a niche situation.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Running webserver and other code simultaneously
@pythoncoder
I think there is some bug in uasyncio lib. More info here:
https://github.com/micropython/micropyt ... issues/335
Could you be so kind and take a look?
Best regards,
MvincM
I think there is some bug in uasyncio lib. More info here:
https://github.com/micropython/micropyt ... issues/335
Could you be so kind and take a look?
Best regards,
MvincM
Re: Running webserver and other code simultaneously
I just removed False from that function call on line 60 in uasyncio/__init__.py, and it works for me now - this is the diff output:
Code: Select all
60c60
< self.poller.unregister(sock, False)
---
> self.poller.unregister(sock)
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Running webserver and other code simultaneously
If you have that "False" in there, you are probably using the uasyncio version of pfalcon which is incompatible with the mainline micropython firmware. Make sure to use the version of uasyncio published at github.com/micropython/micropython-lib
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Running webserver and other code simultaneously
I can confirm. In the main line of uasyncio libs, there is no "False" so the problem is still there...
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Running webserver and other code simultaneously
This issue is discussed here with means of ensuring the correct library is installed.
I use uasyncio daily and it does not throw this error. The uasyncio version must match the firmware.
I use uasyncio daily and it does not throw this error. The uasyncio version must match the firmware.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Running webserver and other code simultaneously
Peter, didn't you want to point at https://github.com/peterhinch/micropython-async
Re: Running webserver and other code simultaneously
Take a look here:
https://github.com/micropython/micropyt ... issues/335
Problem is gone! Thanks, everyone!
MvincM
https://github.com/micropython/micropyt ... issues/335
Problem is gone! Thanks, everyone!
MvincM
Re: Running webserver and other code simultaneously
BTW...
I have read a tutorial for uasyncio but I can't understand main difference "call_soon vs create_task". When we should use which function?
Like in this example:
https://github.com/micropython/micropyt ... _server.py
Why we use call_soon instead create_task (both works well).
Could someone be so kind and explain to me?
Best regards,
MvincM
I have read a tutorial for uasyncio but I can't understand main difference "call_soon vs create_task". When we should use which function?
Like in this example:
https://github.com/micropython/micropyt ... _server.py
Why we use call_soon instead create_task (both works well).
Could someone be so kind and explain to me?
Best regards,
MvincM
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Running webserver and other code simultaneously
call_soon is intended for callback functions (i.e. synchronous code defined with def foo(args)). create_task is for coroutines defined with async def foo(args).
A point of contention with the asyncio paradigm is the distinction between synchronous and asynchronous functions: this has become known as "the red and blue function problem". I recommend you read this excellent article for background. Python's asyncio (and uasyncio) do maintain this distinction. In MicroPython one is a function (obviously) and the other is a generator.
A point of contention with the asyncio paradigm is the distinction between synchronous and asynchronous functions: this has become known as "the red and blue function problem". I recommend you read this excellent article for background. Python's asyncio (and uasyncio) do maintain this distinction. In MicroPython one is a function (obviously) and the other is a generator.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.