rogerxavier commited on
Commit
7ca96aa
1 Parent(s): 420a82a

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +13 -1
api.py CHANGED
@@ -10,7 +10,8 @@ from moviepyTest import test
10
  from typing import *
11
  from fastapi.responses import PlainTextResponse #执行其他py的plaintext返回
12
  import subprocess
13
-
 
14
  app = FastAPI()
15
 
16
  @app.get("/inference")
@@ -58,4 +59,15 @@ async def execute_py_file(file_name: str):
58
  except subprocess.CalledProcessError as e:
59
  return PlainTextResponse(f"Error executing {file_name}.py: {e}")
60
 
 
 
 
 
 
 
 
 
 
 
 
61
 
 
10
  from typing import *
11
  from fastapi.responses import PlainTextResponse #执行其他py的plaintext返回
12
  import subprocess
13
+ from fastapi import BackgroundTasks
14
+ import time
15
  app = FastAPI()
16
 
17
  @app.get("/inference")
 
59
  except subprocess.CalledProcessError as e:
60
  return PlainTextResponse(f"Error executing {file_name}.py: {e}")
61
 
62
+
63
+ def someTask():
64
+ time.sleep(2)
65
+ print("睡眠2s结束")
66
+
67
+ @app.get("/backTaskTest")
68
+ def returnRandomSubscribeUrl(background_tasks: BackgroundTasks)->str:
69
+ #返回
70
+ result = "先返回"
71
+ background_tasks.add_task(someTask)
72
+ return result
73