[Snek] Stopping a runaway program

Keith Packard keithp at keithp.com
Sun Apr 12 12:11:24 PDT 2020


"Misha Gusarov" <dottedmag at dottedmag.net> writes:

> Hi.
>
> How should a runaway Snek program be stopped?
>
> The problem I'm trying to solve is the following: I'd like to run a 
> program from "EEPROM"
> on start on Lego EV3, but I find that even trivial
>
>> while True: print("hello world")
>
> can't be stopped via "serial" (actually network) – snek is busy 
> outputting data, and does
> not stop to read Ctrl-C from stdin.

On embedded hardware, I've been handling this by having the serial
interrupt handler look for ^C and setting snek_abort.

On the EV3, I'd suggest creating a signal handler which catches SIGINT
and have that set snek_abort, then your wrapping program can look for ^C
in its input stream and send a SIGINT to snek.

Alternatively, you could have a separate thread reading input and
queuing that for the main thread, while checking for ^C in that input
stream to set snek_abort.

> If that does not work, then running anything at startup is a recipe for 
> disaster: the only
> way to clear a bad for program will be SSHing to the EV3 and removing 
> the stored program.

Yup, you definitely need some way to set snek_abort that doesn't require
the main thread to see it.

I saw your snekserver thread; will take a closer look at that shortly.

-- 
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://keithp.com/pipermail/snek/attachments/20200412/8126454b/attachment.sig>


More information about the Snek mailing list