better error handling, try to avoid segfault in sillytavern
This commit is contained in:
parent
c05d195583
commit
2378a29bde
1 changed files with 42 additions and 36 deletions
10
koboldcpp.py
10
koboldcpp.py
|
@ -568,6 +568,7 @@ class ServerRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||
current_token = 0
|
||||
incomplete_token_buffer = bytearray()
|
||||
await asyncio.sleep(0.05) #anti race condition, prevent check from overtaking generate
|
||||
try:
|
||||
while True:
|
||||
streamDone = handle.has_finished() #exit next loop on done
|
||||
tokenStr = ""
|
||||
|
@ -605,6 +606,9 @@ class ServerRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||
if api_format == 4: # if oai chat, send last [DONE] message consistent with openai format
|
||||
await self.send_oai_sse_event('[DONE]')
|
||||
break
|
||||
except Exception as ex:
|
||||
print("SSE streaming was interrupted due to an exception")
|
||||
print(ex)
|
||||
|
||||
# flush buffers, sleep a bit to make sure all data sent, and then force close the connection
|
||||
self.wfile.flush()
|
||||
|
@ -629,7 +633,7 @@ class ServerRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||
except (BrokenPipeError, ConnectionAbortedError) as cae: # attempt to abort if connection lost
|
||||
print(cae)
|
||||
handle.abort_generate()
|
||||
time.sleep(0.1) #short delay
|
||||
time.sleep(0.2) #short delay
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
@ -938,8 +942,10 @@ Enter Prompt:<br>
|
|||
self.send_header('content-length', str(len(genresp)))
|
||||
self.end_headers(content_type='application/json')
|
||||
self.wfile.write(genresp)
|
||||
except:
|
||||
except Exception as ex:
|
||||
print("Generate: The response could not be sent, maybe connection was terminated?")
|
||||
handle.abort_generate()
|
||||
time.sleep(0.2) #short delay
|
||||
return
|
||||
finally:
|
||||
modelbusy.release()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue