Page 2 of 3

Re: Running webserver and other code simultaneously

Posted: Tue Jun 05, 2018 6:55 am
by pythoncoder
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.

Re: Running webserver and other code simultaneously

Posted: Tue Apr 02, 2019 8:51 am
by mvincm
@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

Re: Running webserver and other code simultaneously

Posted: Tue Apr 02, 2019 10:39 am
by simonmcc
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)

Re: Running webserver and other code simultaneously

Posted: Tue Apr 02, 2019 10:54 am
by kevinkk525
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

Re: Running webserver and other code simultaneously

Posted: Tue Apr 02, 2019 12:01 pm
by mvincm
I can confirm. In the main line of uasyncio libs, there is no "False" so the problem is still there...

Re: Running webserver and other code simultaneously

Posted: Tue Apr 02, 2019 4:31 pm
by pythoncoder
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.

Re: Running webserver and other code simultaneously

Posted: Tue Apr 02, 2019 7:02 pm
by Roberthh
Peter, didn't you want to point at https://github.com/peterhinch/micropython-async

Re: Running webserver and other code simultaneously

Posted: Tue Apr 02, 2019 7:13 pm
by mvincm
Take a look here:

https://github.com/micropython/micropyt ... issues/335

Problem is gone! Thanks, everyone!

MvincM

Re: Running webserver and other code simultaneously

Posted: Wed Apr 03, 2019 8:57 pm
by mvincm
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

Re: Running webserver and other code simultaneously

Posted: Fri Apr 05, 2019 7:59 am
by pythoncoder
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.