Using shell object to restart python script

Laura Papke's icon

Hello, quick question, I am trying to use the shell object in max to restart a python script in case it stops. I unfortunately have a hard time understanding how to send commands. I assume a directory needs to be assigned as well as it needs a message to stop the current process and to restart it. I tried to go through the help file, read through some comments online and asked chat gpt but my coding skills are still very basic so I can't get my head around it. Maybe someone here has some knowledge? That would be great. Below my patch and the python code attached.

tides_code.txt
txt
Max Patch
Copy patch and select New From Clipboard in Max.

TFL's icon

First, test your commands in a regular terminal. You might get more info from the output there than from the Max console.

Maybe your tides_code.py doesn't work (which is the case for me, as I'm missing the required modules).

Other than that, your commands seems right and should work.

JBG's icon

Your approach seems sound, but if the issue is that your script works in a terminal but not in Max, the problem is probably what "python3" refers to in this context. A terminal will handle a lot of initialization that's hidden to the user (zshrc, $PATH variable, conda/venv/pyenv initialization, etc.) which isn't available in the raw [shell].

Try to run which python3 in a terminal and then in the [shell] . Personally, I get /opt/homebrew/Caskroom/miniconda/base/bin/python3 in the terminal and /usr/bin/python3 in the [shell]. The latter is a different installation of python that MacOS uses internally, which you really shouldn't be using at all (and where none of your installed packages are available).

In my case, I would instead run the full command like this (but with the path that you get from running which python3 in the terminal), rather than relying on the python3 alias:

Also, if you check the "Merge STDERR With STDOUT" flag in the [shell] object's inspector, debugging will become much easier!