Running multiple python scripts in parallel at boot

  Kiến thức lập trình

At the moment I’m trying to run two scripts in parallel at boot on a raspberry pi 3B+. However, the problem I’m sunning into is the first script to stop when the second starts.

The following code is saved in a .sh:

#!/bin/bash

# Start a new tmux session named 'script1' and run the first Python script

tmux new-session -d -s script1 "/usr/bin/python3 /home/pi/script1.py > /home/pi/script1.log 2>&1"
echo "Started script1 session at $(date)" >> /home/pi/test.log

# Wait for 2 seconds before starting the next session

sleep 2

# Start a new tmux session named 'script2' and run the second Python script

tmux new-session -d -s script2 "/usr/bin/python3 /home/pi/script2.py > /home/pi/script2.log 2>&1"
echo "Started script2 session at $(date)" >> /home/pi/test.log’

With the use of crontab @reboot I’m running the script.

The script runs fine I.e. logging tells me each script starts. But when I tmux attach via the terminal, there is only one running script to show. Tmux tells me “no more sessions running” if I CTRL+B and N to the assumed next tmux session.

My question is what my code should look like to have the scripts run in parallel continuously.

All help is appreciated

I tried running the scripts separately in the terminal. That worked. This incates the scripts are fine. The same I tried with the tmux commands. Same result. But running it in parallel did not work

New contributor

Maurits is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT