Python Forum

Full Version: Running multiple script at the same time
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I'm new with Python and I'm trying to learn it.

I would like to know how can I start/run several python scrip at the same time. I'm not familiar with it, do you have any good references where I could learn that?

More details:

For now I have two scripts (others may be added):
1: A script that takes some specific frames in a video stream and save them in a folder
2: A script that takes the frames of the folder (when he starts to be filled by script 1) and processes it.

Both script need to run "forever" with a loop (for now, I'm using 'While(True):' on both)

How could I run them simultaneously, in a way that they don't enter in conflict or interrupt each other, and which way should I use for me to be able to stop easily the 2 forever loop if needed?

Thank you
You can use threading. Place both scripts in the same folder and write a third script.
In this third script import the other two, lets call them capture and process and assume that they both have a main function.
If they don't have a main function or you have problems making this work, consider posting your code.
from threading import Thread
import capture
import process

capturer = Thread(target=capture.main, daemon=True)
capturer.start()

processor = Thread(target=process.main, daemon=True)
processor.start()
This will start both scripts as individual processes. The will run even if you close the console that launched them.