0

I am making an API to launch apps from my phone to my pc but when I access the route to the API the page won't load until the program launched with os.system() is closed

Here is my code:

import os
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    os.system("notepad")
    return "<p>Hello, World!<br>Launching Notepad!</p>"

Thanks in advance for the help! Ps.: I am new to flask and APIs in general.

davidism
  • 121,510
  • 29
  • 395
  • 339
Zariaa_
  • 116
  • 1
  • 6
  • 1
    Related: https://stackoverflow.com/questions/48252631/python-calling-script-without-waiting-for-it-to-execute – Alexander Santos Oct 01 '21 at 16:03
  • That's probably because the opened program blocks further execution of the view. Take a look, for example, at https://stackoverflow.com/a/27625288/4183498. – Dušan Maďar Oct 01 '21 at 16:03

1 Answers1

1

os.system does not return until the process it started has exited.

Take a look at the subprocess module to start processes in the background. In the simplest case:

import subprocess
subprocess.Popen("notepad")
Thomas
  • 174,939
  • 50
  • 355
  • 478