This is mostly a conceptual question. Is it possible to have two scripts running on a Raspberry Pi, where one is a Julia script, and one is a Python script? In the most general case of this, is there an obvious reason this wouldn't work?
Assuming that you're not running a weird custom operating system with a minimal kernel, the RPi is running a full fledged version of linux. The applications it comes with are written in C, C++, Java, Perl, Python, and probably others. You'll have to install Julia, but there's no reason the RPi can't handle multiple languages.
You can run any number of scripts with varying programming language. You can think in the direction of using tools like
tmux. They basically are used to run scripts in background or detached mode. This proves to be quite useful when you have a lot of applications you need to keep track of whilst they are running in the background.
Installation on Raspberry Pi
I am a fan of
screen hence on your Pi you can install
tmux via the following command line:
sudo apt install tmux
apt-get install can work too)
Working around with
Think of a your two scripts running together as a Session in
tmux. Since you have two scripts in mind (Julia and Python); you should consider running each of the script in it's own Window.
tmux session starts it will consist of two windows:
- an empty
if both scripts work well, all you have to do is attach to the Session and navigate to each Window using the
tmux hot-keys (usually CTRL+B+window_Number)
Here is a what your
tmux script would look like (called
#!/usr/bin/bash # 1. Create a detached Session using tmux /usr/bin/tmux new-session -d -s MySession # 2. Use the below line to catch any errors in the scripts /usr/bin/tmux set-option -t TWIN set-remain-on-exit on # 3. Create a window for Julia Script /usr/bin/tmux new-window -d -n 'juliaScript' -t MySession:1 'julia /home/pi/myJuliaScript.jl' # 4. Create a window for Python Script /usr/bin/tmux new-window -d -n 'pyScript' -t MySession:1 'python3 /home/pi/myPythonScript.py' # Safely exit exit 0
Execution and Handling Session
Once the above mentioned script is written, give executable rights using:
chmod +x sessionScript.sh
and execute it using :
This will trigger a new
tmux session called : MySession with windows juliaScript and pyScript
In order to attach to the script:
You will be attached to the session and see a blank shell, in order to see how your Julia Script is doing use: CTRL+B+1
For your python script use: CTRL+B+2
If you want to keep the session running and detach from the session use: CTRL+B+D
If you want to kill the complete session:
You can run as many scripts (not infinite though! but a decent number) on the Pi or any Linux machine using
tmux. Learn it and soon you will love it.
I second Shan-Desai's suggestion of
tmux, which is great, but perhaps this is actually overkill for your application. If neither of the scripts is in some way interactive, requires user input etc., you can simply run them in parallel with Bash's
$ julia myJuliaScript.jl & python3 myPythonScript.py
This will keep the terminal “hanging” while either of the scripts still runs; depending on what you need this for this may not matter. If you want to log out and keep the scripts running, you can use
nohup, which comes installed by default on most Unixes:
$ nohup sh -c 'julia myJuliaScript.jl & python3 myPythonScript.py' & $ logout # Scripts keep running
This also works with just a single script.
$ nohup julia myJuliaScript.jl & $ logout
If the scripts print output to the console, I'd recommend directing it into a file:
$ (julia myJuliaScript.jl > jlScript.log) & (python3 myPythonScript.py > pyScript.log)
If one of the scripts is really interactive both producing output and requiring input, then
tmux is indeed probably the best tool.