I'm writing a server for sending rendered images to clients (browsers) using Flask. Since an image maybe not ready (is still rendering), I wrote the following code to wait for a rendering thread until it finishes.
@app_autoView.route("/autoviewimgs/<origin>/<identifier>")
def autoviewimgs(origin, identifier):
if identifier in renderThreads:
renderThreads[identifier].join()
return flask.send_from_directory(f'./latentspace/autoview/{origin}', identifier + '.png')
However, it seems the entire server start to wait for a single thread, and all other HTTP requests are blocked...
I don't know if python-threading is suitable for Flask or alternative ways of doing this...
I have tried Celery as suggested by @ParthS007, but the server was still blocked, as shown in the following code:
@app_autoView.route("/autoviewimgs/<origin>/<identifier>")
def autoviewimgs(origin, identifier):
if identifier in renderThreads:
if not renderThreads[identifier].ready():
casename = renderThreads[identifier].get()
return flask.send_from_directory(f'./latentspace/autoview/{origin}', identifier + '.png')
threadingin Flask?