aletrn commited on
Commit
98cbe02
·
1 Parent(s): 03b4782

[feat] try handling missing folder at WRITE_TMP_ON_DISK env

Browse files
Files changed (1) hide show
  1. wrappers/fastapi_wrapper.py +7 -1
wrappers/fastapi_wrapper.py CHANGED
@@ -1,6 +1,7 @@
1
  import json
2
  import os
3
  import uuid
 
4
 
5
  from fastapi import FastAPI, HTTPException, Request, status
6
  from fastapi.exceptions import RequestValidationError
@@ -129,7 +130,12 @@ async def http_exception_handler(request: Request, exc: HTTPException) -> JSONRe
129
  write_tmp_on_disk = os.getenv("WRITE_TMP_ON_DISK", "")
130
  app_logger.info(f"write_tmp_on_disk:{write_tmp_on_disk}.")
131
  if bool(write_tmp_on_disk):
132
- app.mount("/vis_output", StaticFiles(directory=write_tmp_on_disk), name="vis_output")
 
 
 
 
 
133
  templates = Jinja2Templates(directory=PROJECT_ROOT_FOLDER / "static")
134
 
135
 
 
1
  import json
2
  import os
3
  import uuid
4
+ import pathlib
5
 
6
  from fastapi import FastAPI, HTTPException, Request, status
7
  from fastapi.exceptions import RequestValidationError
 
130
  write_tmp_on_disk = os.getenv("WRITE_TMP_ON_DISK", "")
131
  app_logger.info(f"write_tmp_on_disk:{write_tmp_on_disk}.")
132
  if bool(write_tmp_on_disk):
133
+ try:
134
+ app.mount("/vis_output", StaticFiles(directory=write_tmp_on_disk), name="vis_output")
135
+ except RuntimeError:
136
+ pathlib.Path.unlink(write_tmp_on_disk, missing_ok=True)
137
+ os.makedirs(write_tmp_on_disk, exist_ok=True)
138
+ app.mount("/vis_output", StaticFiles(directory=write_tmp_on_disk), name="vis_output")
139
  templates = Jinja2Templates(directory=PROJECT_ROOT_FOLDER / "static")
140
 
141