how do I run multiple python scripts simultaniously using QProcess

Viewed 83

I am trying to run multiple python scripts simultanuosly using QProcess from inside a GUI. The following will execute the first script and throw QProcess::start: Process is already running for the other two scripts.

def run(self):
    self.p = QtCore.QProcess()
    scripts = ['python ./scripts/s1.py', 'python ./scripts/s2.py', 'python ./scripts/s3.py']
    for s in scripts:            
        self.p.start(s)
1 Answers

You can't reuse the same QProcess if it's already running, as the error reports.

Just create a list of processes instead:

    def run(self):
        self.processes = []
        scripts = [
            'python ./scripts/s1.py', 
            'python ./scripts/s2.py', 
            'python ./scripts/s3.py'
        ]
        for script in scripts:
            process = QtCore.QProcess()
            self.processes.append(process)
            process.start(script)
Related