Python Forum
Running multiple script at the same time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running multiple script at the same time
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using a script to open multiple shells? SuchUmami 9 509 Apr-01-2024, 10:04 AM
Last Post: Gribouillis
  No Internet connection when running a Python script basil_555 8 607 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 492 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Help Running Python Script in Mac OS emojistickers 0 348 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  Trying to make a board with turtle, nothing happens when running script Quascia 3 678 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Python script running under windows over nssm.exe JaroslavZ 0 718 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,283 May-10-2023, 02:13 PM
Last Post: Calab
  Running script with subprocess in another directory paul18fr 1 3,796 Jan-20-2023, 02:33 PM
Last Post: paul18fr
  Multiple.ui windows showing at the same time when I only want to show at a time eyavuz21 4 1,034 Dec-20-2022, 05:14 AM
Last Post: deanhystad
Question Running an action only if time condition is met alexbca 5 1,317 Oct-27-2022, 02:15 PM
Last Post: alexbca

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020