This commit is contained in:
linghaihui 2023-03-26 09:19:37 +08:00
parent 3f2d028ba6
commit fa594f2aaa

View File

@ -19,6 +19,7 @@ BAK_COOKIE = os.environ.get('COOKIE_FILE1', '')
BAK_COOKIE1 = os.environ.get('COOKIE_FILE2', '') BAK_COOKIE1 = os.environ.get('COOKIE_FILE2', '')
LOCK = threading.Lock() LOCK = threading.Lock()
BOT_LOCK = threading.Lock()
def reset_cookie(): def reset_cookie():
@ -43,10 +44,13 @@ bots = {}
def get_bot(sid): def get_bot(sid):
BOT_LOCK.acquire(timeout=5)
if sid in bots: if sid in bots:
BOT_LOCK.release()
return bots[sid] return bots[sid]
bot = Chatbot() bot = Chatbot()
bots[sid] = bot bots[sid] = bot
BOT_LOCK.release()
return bot return bot
@ -90,8 +94,8 @@ async def chat(request):
'text': text, 'text': text,
'suggests': suggests, 'suggests': suggests,
'message': msg, 'message': msg,
'num_in_conversation': res['item']['throttling']['numUserMessagesInConversation'] if 'throttling' in 'num_in_conversation': res['item']['throttling']['numUserMessagesInConversation']
res['item'] else -1, if 'throttling' in res['item'] else -1,
}, },
'cookie': os.environ.get('COOKIE_FILE') 'cookie': os.environ.get('COOKIE_FILE')
}) })
@ -111,4 +115,4 @@ async def openid(request):
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, workers=4) app.run(host='0.0.0.0', port=8000)