When I run this code locally:
<code>import subprocess
print('before')
subprocess.run(['python', 'target_script.py', 'arg1', 'arg2'])
print('after')
</code>
<code>import subprocess
print('before')
subprocess.run(['python', 'target_script.py', 'arg1', 'arg2'])
print('after')
</code>
import subprocess
print('before')
subprocess.run(['python', 'target_script.py', 'arg1', 'arg2'])
print('after')
Output:
<code>before
after
</code>
<code>before
after
</code>
before
after
But when I run the same code in FastAPI…
<code>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)
</code>
<code>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)
</code>
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)
<code>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)
</code>
<code>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)
</code>
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)
<code>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)
</code>
<code>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)
</code>
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