Fixed billions of async processes being created and waiting by adding a timeout
This commit is contained in:
parent
819d3cbade
commit
3c3d9a2f38
15
main
15
main
|
@ -320,16 +320,25 @@ async def waitforedit():
|
||||||
secretKey = data["secretKey"]
|
secretKey = data["secretKey"]
|
||||||
userCookie = get_session(secretKey)
|
userCookie = get_session(secretKey)
|
||||||
user = get_user(userCookie["id"])
|
user = get_user(userCookie["id"])
|
||||||
|
complete = true
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
while user["id"] not in messages or not messages[user["id"]]:
|
while user["id"] not in messages or not messages[user["id"]]:
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
elapsed_time = time.time() - start_time
|
||||||
|
if elapsed_time >= 20:
|
||||||
|
break
|
||||||
|
complete = false
|
||||||
|
|
||||||
message = messages[user["id"]].pop(0)
|
message = messages[user["id"]].pop(0)
|
||||||
del messages[user["id"]]
|
del messages[user["id"]]
|
||||||
|
|
||||||
return {
|
if complete == true:
|
||||||
"note": message
|
return {
|
||||||
}, 200
|
"note": message
|
||||||
|
}, 200
|
||||||
|
else:
|
||||||
|
return 400
|
||||||
|
|
||||||
@app.route("/api/editnote", methods=("GET", "POST"))
|
@app.route("/api/editnote", methods=("GET", "POST"))
|
||||||
async def apieditnote():
|
async def apieditnote():
|
||||||
|
|
Loading…
Reference in New Issue