I am trying to run a web application on glitch. I have one Flask based python file that is already running (call that a.py). I want to have another application (b.py) running concurrently on the same project. Is this possible?
I have tried: ` “start”: “PYTHONUNBUFFERED=true python3 a.py && python3 b.py” in my glitch.json but it does not seem to work.
I’m not sure if this is going to work and I have not tested it.
You could create a start-point python file start.py that runs the other two files concurrently using threading and shell command.
Ressources
How to run a shell command with python from janakiev.com
import os
import threading
def execute_script(name):
os.system('python ' + name)
// Execute a.py on a thread (concurrently)
a = threading.Thread(target=execute_script, args=('a.py',))
a.start()
// Execute b.py on a thread (concurrently)
b = threading.Thread(target=execute_script, args=('b.py',))
b.start()
// Block main execution until a.py is terminated
a.join()
// Block main execution until b.py is terminated
b.join()
Also note that you can change PYTHONUNBUFFERED=true python3 a.py && python3 b.py to run the processes in the background: PYTHONUNBUFFERED=true python3 a.py & python3 b.py &. 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.