1

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?

10

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.

10

You can run any number of scripts with varying programming language. You can think in the direction of using tools like Screen or 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 tmux over 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 tmux

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.

Once your tmux session starts it will consist of two windows:

  1. an empty bash shell
  2. myJuliascript
  3. myPythonScript

Working

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)

tmux Script

Here is a what your tmux script would look like (called sessionScript.sh):

#!/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 : ./sessionScript.sh

This will trigger a new tmux session called : MySession with windows juliaScript and pyScript

  1. In order to attach to the script:

     tmux a
    
  2. 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

  3. For your python script use: CTRL+B+2

  4. If you want to keep the session running and detach from the session use: CTRL+B+D

  5. If you want to kill the complete session: tmux kill-session

Note:

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.

  • 3
    I'm not quite sure this is what the OP had in mind, but +1 for good information and in such good detail. I'd give it an extra +1 if I could for using tmux over screen... ;) – Jacobm001 Mar 3 '17 at 16:55
  • Thought OP's general question could be tackled with a practical workthrough. Plus answer can help for future references on multi-programming applications on Pi. – Shan-Desai Mar 3 '17 at 16:56
6

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 & operator:

$ 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.

3

No, there are no obvious reasons why you wouldn't be able to run two scripts in two languages at the same time. The Pi's just a very wee, relatively low-powered Linux machine and is perfectly capable of doing several things at once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.