Running two python scripts in parallel

I am trying to run a web application on glitch. I have one Flask based python file that is already running (call that I want to have another application ( running concurrently on the same project. Is this possible?

I have tried: ` “start”: “PYTHONUNBUFFERED=true python3 && python3” in my glitch.json but it does not seem to work.

Any advise would be super helpful!


I’m not sure if this is going to work and I have not tested it.
You could create a start-point python file that runs the other two files concurrently using threading and shell command.


Sample code (NOT TESTED - may need some tweaking)

import os
import threading

def execute_script(name):
    os.system('python ' + name)

// Execute on a thread (concurrently)
a = threading.Thread(target=execute_script, args=('',))

// Execute on a thread (concurrently)
b = threading.Thread(target=execute_script, args=('',))

// Block main execution until is terminated
// Block main execution until is terminated

Hope this helps.

Also note that you can change PYTHONUNBUFFERED=true python3 && python3 to run the processes in the background: PYTHONUNBUFFERED=true python3 & python3 &. However, @Joprocorp’s solution using threading from python itself is the best way to go, especially as you get far more control over the scripts.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.