Page 1 of 1

How do I terminate a background program/thread/function/method in uPy?

Posted: Thu Jan 31, 2019 5:48 pm
by sunbear
I was running the Basic WiFi configuration script provided in help(). Unfortunately, I did a typo in one of the args for the .connect() method. Thereafter, my terminal was flooded with the family of msgs relating to "wifi: STA_DISCONNECTED, reason:15" which I understand it to mean "15 4-Way Handshake timeout". The stop the barrage of msgs, I did a Ctrl+C. That got me the >>> prompt but still it would subsequently be overtaken by error msgs. I tried Ctrl+D but that did not stop the constant stream of error msg. So I did a hard reset.

How do I terminate a background program/thread/function/method in uPy? Pardon my asking, I am new here.

In Linux, I use the ps cmd to see my processes and kill them accordingly. How do I do an equivalent here? Thanks.

Re: How do I terminate a background program/thread/function/method in uPy?

Posted: Fri Feb 01, 2019 12:20 am
by Hanilein
uPy runs 'on the bare metal', there is no such thing as a task manager or background process to 'break' a rouge piece of code.

I use a pyBoard, and the code lives on an SD-Card. If i stuff up, i pull the SD-card, put it in the laptop, change the code and the problem is solved. Happens pretty seldom, but it does.

There are other tricks, but one need to know a bit more about the hardware and the code you are using.

Re: How do I terminate a background program/thread/function/method in uPy?

Posted: Fri Feb 01, 2019 5:04 am
by sunbear
I was running uPy on esp32 devkit v1 with no SD card. Any "trick" for this? ;)

Will pulling out the SD-card for your system reduce the life-span of the card?

Re: How do I terminate a background program/thread/function/method in uPy?

Posted: Fri Feb 01, 2019 7:30 am
by pythoncoder
Re SD cards: best to power down the Pyboard first.

Re dodgy code this problem really only arises if you put code in main.py, because the code will automatically run (and fail) again if you reset the board. It's best to put code in your own module and test it at the REPL. That way you can stop it with ctrl-c or soft reset with ctrl-d.

If you want your application to auto-start, the very last thing to do once it's fully tested is to edit main.py to include a single line of code which starts your application.

Re: How do I terminate a background program/thread/function/method in uPy?

Posted: Fri Feb 01, 2019 7:55 am
by Christian Walther
Try just ignoring the error messages and typing over them, I expect that even though you can’t see what you type, the REPL should still be functional and you should be able to turn off the WiFi that way.

Re: How do I terminate a background program/thread/function/method in uPy?

Posted: Fri Feb 01, 2019 8:54 am
by sunbear
I came across this https://www.freertos.org/a00021.html#vTaskList. Are these task utilities exposed in any uPy module that a user can use on an esp32?

@pythoncoder Thanks for the "tips".