server.py
from fastapi import FastAPI
import uvicorn
import time
app = FastAPI()
@app.post('/upload')
async def upload(file: dict):
print('hello')
time.sleep(1)
return file
if __name__ == '__main__':
uvicorn.run(app, host='', port=1024)
client.py
import requests
import threading
def thread_main(a):
response = requests.post(url, json={'0':0, '1':1, '2':2})
if response.status_code == 200:
print(a, response.json())
else:
print(a, 'wrong')
url = 'http://IP:1024/upload'
for i in range(10):
thread = threading.Thread(target=thread_main, args=(i,))
thread.start()
server logs are ''' hello INFO: IP:port - "POST /upload HTTP/1.1" 200 OK hello INFO: IP:port - "POST /upload HTTP/1.1" 200 OK hello INFO: IP:port - "POST /upload HTTP/1.1" 200 OK ... '''
but i want them to be ''' hello hello hello ... INFO: IP:port - "POST /upload HTTP/1.1" 200 OK INFO: IP:port - "POST /upload HTTP/1.1" 200 OK INFO: IP:port - "POST /upload HTTP/1.1" 200 OK ... '''
is it possible in fastapi?
i thought that using 'async' means server process requests asynchronously but it doesn't
additionally how do I know if the function is a blocking function? and how do i find an alternative function?