When data is written to a file in FastAPI like below, is this thread safe? Assuming that several requests are sent to the endpoint at the same time.
@app.post("/items/")
def add_item(item: str)
with open('output.txt', 'w') as f:
f.write(item + '\n')
return item
And if not, what would be a good way to ensure that each item is written to the file.