Raspberry Pi

How to Run Multiple Python Programs Simultaneously on Raspberry Pi

Due to the increasing demand of Python programming, you may need to run multiple Python programs simultaneously at some stage to save your time or integrating the output of one code with other. In that case, you may need help in running multiple Python programs simultaneously. To do this, you need to follow this article guide.

How Can I Run Multiple Python Programs Simultaneously

Running multiple python program on Raspberry Pi isn’t difficult and you can easily do using the following steps:

Step 1: First open any Python IDE on your Raspberry Pi system. Here I am using Thonny IDE in that case.

Inside the Thonny IDE, you will find the guide to write and run Python code as shown in the image below:

Step 2: Now, let’s write our first code, which could be any Python code.

In my case, the code is shown below:

first_name = "Linux Hint"
favorite_language = "Python"

print(f"Hi, I'm {first_name}. I'm learning {favorite_language}.")

Save the file by choosing any suitable name for files. In my case, I saved with a name of “code1.py”.

Step 3: Let’s open another tab on Thonny IDE and put another python code inside it, which is shown below:

print("Hello LinuxHint Followers")

Save the file with a proper name. In my case, the second file is named as “code2.py”.

You can write multiple codes you want inside the Thonny IDE.

Note: Make sure both codes are successfully running on Thonny IDE.

To simultaneously run the Python programs, we have to use “import os” command with the program’s locations using the following code:

import os
os.system('python3 /home/pi/code1.py')
os.system('python3 /home/pi/code2.py')

Note: The above code must be written in a separated file and placed in the same directory where the above codes are placed.

To run the code, use the “Run” button:

Here you can see from the above output that we have successfully run multiple Python Programs simultaneously using Thonny IDE on Raspberry Pi system. Similar type of coding technique would be adopted for Python terminal.

Conclusion

Most users want to do multiple tasks simultaneously with Raspberry Pi device using a single program. Thus, if users are interested in running multiple python programs simultaneously, they can follow the above guide to easily run multiple programs using Thonny IDE on Raspberry Pi system.

About the author

Muhammad Nasir

Hi! I am an engineer and technical blogger by profession and I enjoy getting things done with electronics. I am using this platform to share my knowledge in the field of Raspberry Pi, Linux, and Embedded Systems with others.