When I run this code locally:
import subprocess
print('before')
subprocess.run(['python', 'target_script.py', 'arg1', 'arg2'])
print('after')
Output:
before
after
But when I run the same code in FastAPI…
from fastapi import FastAPI
import subprocess
app = FastAPI()
@app.get('/')
def index():
subprocess.run(['python', 'target_script.py', 'arg1', 'arg2'])
if __name__ == '__main__':
from uvicorn import run
run(app, port=80)
Output: (when I start the app)
INFO: Started server process [3568]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:80 (Press CTRL+C to quit)
Output: (when I enter the index page)
INFO: Started server process [3568]
INFO: Waiting for application startup.
INFO: ASGI 'lifespan' protocol appears unsupported.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
I want the process to not be related with uvicorn process.
What should I do?
7