Fix some potential issues related to threads.
This commit is contained in:
parent
8074a58a1a
commit
6de6246dd4
12
main.py
12
main.py
|
@ -371,6 +371,18 @@ class PromptQueue:
|
|||
return True
|
||||
return False
|
||||
|
||||
def get_history(self):
|
||||
with self.mutex:
|
||||
return copy.deepcopy(self.history)
|
||||
|
||||
def wipe_history(self):
|
||||
with self.mutex:
|
||||
self.history = {}
|
||||
|
||||
def delete_history_item(self, id_to_delete):
|
||||
with self.mutex:
|
||||
self.history.pop(id_to_delete, None)
|
||||
|
||||
async def run(server, address='', port=8188):
|
||||
await asyncio.gather(server.start(address, port), server.publish_loop())
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ class PromptServer():
|
|||
|
||||
@routes.get("/history")
|
||||
async def get_history(request):
|
||||
return web.json_response(self.prompt_queue.history)
|
||||
return web.json_response(self.prompt_queue.get_history())
|
||||
|
||||
@routes.get("/queue")
|
||||
async def get_queue(request):
|
||||
|
@ -146,11 +146,11 @@ class PromptServer():
|
|||
json_data = await request.json()
|
||||
if "clear" in json_data:
|
||||
if json_data["clear"]:
|
||||
self.prompt_queue.history = {}
|
||||
self.prompt_queue.wipe_history()
|
||||
if "delete" in json_data:
|
||||
to_delete = json_data['delete']
|
||||
for id_to_delete in to_delete:
|
||||
self.prompt_queue.history.pop(id_to_delete, None)
|
||||
self.prompt_queue.delete_history_item(id_to_delete)
|
||||
|
||||
return web.Response(status=200)
|
||||
|
||||
|
|
Loading…
Reference in New Issue