Hello there,
I would like to read/find some advise in regards to how to create a "infinity loop" in MicroPython, (specifically Wi Py 2.0). I have done it by doing the following, but I am not so sure it is the best way.
so...I have a python.py file, and I might have the following functions defined and a "main" function inside a while(True)
import <> from <>
def aFuncion1:
#some code here...
def aFuncion2:
#some code here...
def main():
aFuncion1()
aFuncion2()
while(True):
main()
I have the feeling that I am wasting resources here, and there is a better way. so question time!!
Am I right or wrong in my programming approach?
I am not familiar with Threads? is this the way to go?
Any other ways to be more efficient code/ memory usage?
Any doco that I can be pointed to?
C
heers
Colombian
MicroPython
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MicroPython
In my opinion the way you've done it is fine.
Re threads. Avoid them unless you have a clear requirement: they add complexity to the debugging process and use resources. Threads offer one approach when you need concurrency. Say one of your functions were to "block" - i.e. wait for some event such as data to arrive from a source, it would delay the execution of your second function until the data arrived and the function ran to completion. If this was unacceptable one way to resolve the issue would be to run each in separate threads.
Handling concurrency is a relatively advanced programming technique. If you need it and are unfamiliar with it I'd recommend doing some reading on the topic.
Re threads. Avoid them unless you have a clear requirement: they add complexity to the debugging process and use resources. Threads offer one approach when you need concurrency. Say one of your functions were to "block" - i.e. wait for some event such as data to arrive from a source, it would delay the execution of your second function until the data arrived and the function ran to completion. If this was unacceptable one way to resolve the issue would be to run each in separate threads.
Handling concurrency is a relatively advanced programming technique. If you need it and are unfamiliar with it I'd recommend doing some reading on the topic.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 2
- Joined: Mon Mar 27, 2017 8:33 am
Re: MicroPython
Hello Peter,
Thank you for your reply, I appreciate it. I am not really familiar with threads but I will definetily keep your advise in mind. Do you recommend any books in regards to Threads?
Cheers
ColombianAustralia
Thank you for your reply, I appreciate it. I am not really familiar with threads but I will definetily keep your advise in mind. Do you recommend any books in regards to Threads?
Cheers
ColombianAustralia