[Snek] [PATCH v3] snekserver: allow network connections to a snigle Snek instance

Misha Gusarov dottedmag at dottedmag.net
Sun May 17 11:22:40 PDT 2020


Hey Keith,

On 17 May 2020, at 18:56, Keith Packard wrote:

> I'm not sure there's a 'right' and 'wrong' way here; it really depends
> on what environment you're running in. For most embedded Snek systems,
> there isn't a file system, so all there is is a single stored program
> and the REPL.

Right, and if it was a single target it would be easy. I'm mostly 
worrying
about finding a common behaviour for ev3, posix targets, and maybe 
future
targets running under various OSes.

>> * ./snek-ev3, no stored program
>>
>>     -> REPL
>>
>> * ./snek-ev3, a stored program exists
>>
>>     -> Run the program. SIGINT should exit into REPL
>
> Well, if the stored program terminates all on its own, then you should
> end up in the REPL. I feel like this makes these two about the same,
> with an empty stored program doing nothing so that the REPL starts 
> right away.

Ack

>
>> * ./snek-ev3 --file foo.py, no stored program
>>
>>     -> Evaluate foo.py, exit into REPL
>>
>> * ./snek-ev3 --file foo.py, a stored program exists
>>
>>     -> Evaluate foo.py, then run stored program. SIGINT should exit 
>> into
>> REPL
>
> Hrm. Maybe my '--file' option was just a bad idea. I used it while
> debugging to that I could load a pile of code and then explore how it
> worked using the REPL. I just looked at how Python deals with this, 
> and
> that has the '-i' option, which means to go into the REPL after 
> running
> the script instead of terminating. Maybe that's a better interface? At
> least it avoids the question of how to handle 'snek --file foo.py
> bar.py'?

Let's do `-i`. Specifying input files as both arguments and options was
quite confusing for me.

> I suspect rebooting the whole EV3 would be a bit more heavy weight 
> than
> necessary,

Yes, it takes couple of minutes to reboot it.

> are you just restarting snek using exec() or are you trying
> to actually reset within the same executable environment?

My current failed attempt is to loop inside the process. However it 
seems
that it's as easy as execv("/proc/self/exe", argv).

> For the case where you don't have a script specified on the command
> line, I'd suggest following the embedded model and have reset()
> re-initialize the system and re-run any stored program before entering
> the REPL.
>
> When there is a command specified, I can think of several options:
>
>  1) Leave 'reset' undefined (like it is in the desktop build).
>
>  2) Have reset throw an error when running a command line script.
>
>  3) Call exit()
>
>  4) Call exec() passing the same command line options you were given
>
>  5) Call exec() passing an empty command line (which would re-run any
>     stored program and enter the REPL).
>
> It seems like option 1) and 2) are pretty similar, and 2) is likely a
> bit easier. I do like this option as it makes snek with a script on 
> EV3
> work like it does on other posix systems?

>
> 3) doesn't seem like a great choice; the user may have no idea why 
> snek
> exited?
>
> I don't have strong opinions about 4) or 5), although if you are
> implementing reset when there isn't a command line script using 
> exec(),
> it's probably simpler to just use whatever code you've already got?

Let me try 2) — I don't expect much use of scripts-on-command-line for 
this
port anyway outside of testing during development.

Best,
Misha.


More information about the Snek mailing list