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

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
sunbear
Posts: 6
Joined: Thu Jan 31, 2019 5:17 pm

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

Post by sunbear » Thu Jan 31, 2019 5:48 pm

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.

Hanilein
Posts: 20
Joined: Thu Jul 12, 2018 11:40 am
Location: Christchurch, New Zealand

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

Post by Hanilein » Fri Feb 01, 2019 12:20 am

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.
Good decisions are based on experience. Experience is based on bad decisions.

sunbear
Posts: 6
Joined: Thu Jan 31, 2019 5:17 pm

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

Post by sunbear » Fri Feb 01, 2019 5:04 am

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?

User avatar
pythoncoder
Posts: 3216
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Fri Feb 01, 2019 7:30 am

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.
Peter Hinch

Christian Walther
Posts: 23
Joined: Fri Aug 19, 2016 11:55 am

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

Post by Christian Walther » Fri Feb 01, 2019 7:55 am

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.

sunbear
Posts: 6
Joined: Thu Jan 31, 2019 5:17 pm

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

Post by sunbear » Fri Feb 01, 2019 8:54 am

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".

Post Reply