use `sys.exit()` and auto-restart kernel?

34 views
Skip to first unread message

Matt Wilkie

unread,
Apr 6, 2021, 2:02:02 PM4/6/21
to Pyzo
Hi,

I'm working with a bunch of scripts from a 3rd party that often include sys.exit() blocks like the below. Is there way to get the kernel to automatically restart so I don't have to do that? Perhaps only after a specific exit code? I'm having to reboot the kernel every minute or so while going through the work and it's very repetitive.

if len(sys.argv) < 4:
    print(f"Usage: {sys.argv[0]} [in_file] [band#] [out_file] [band #]")
    sys.exit(1)

[...]

if dataset is None:
    print("Unable to open", input, "for reading")
    sys.exit(1)

Matt Wilkie

unread,
Apr 6, 2021, 2:20:01 PM4/6/21
to Pyzo
I found the Ctrl-K restart kernel keyboard shortcut, which makes this a much smaller issue.

Almar Klein

unread,
Apr 7, 2021, 3:58:40 AM4/7/21
to Pyzo
Hi,

I'm glad to hear that the shortcut helps :)

As for automatic restart. This is currently not possible. It would possibly be problematic, e.g. imagine providing a wrong path to the Python interpreter and Pyzo constantly trying to launch it.

Usually, when you work with script that exit in this way, you can also use run-as-script (Ctrl-shift-e), which will also automatically restart the kernel, so you won't even need to Ctrl-k.

Best,
  Almar
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyzo+uns...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages