I have a Python file like this:
print("file begin", flush=True)
import ...
print("some print statements from time to time")
app = FastAPI()
if __name__ == "__main__":
print("starting")
uvicorn.run(app, host="0.0.0.0", port=8080)
All of this is working, but I see no messages in console. I run this inside docker with the command
/opt/conda/bin/python /opt/conda/bin/conda run -n my-env python -m folder.myfile
But when I added error rising like int(input("non integer here"))
I got the exception and all print messages including the first one print("file begin", flush=True)
that must be flushed after the Python file is started.
So if add int(input("non integer here"))
after print("file begin", flush=True)
I got "file begin"
and Exception stack; when I added int(input("non integer here"))
at the end of file I got all other print
statements to work.
What does this happen and how can I fix it?