mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-03-19 13:28:11 +08:00
fix: time type bug
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
class ExpiredDict(dict):
|
||||
def __init__(self, expires_in_seconds):
|
||||
super().__init__()
|
||||
@@ -8,8 +8,7 @@ class ExpiredDict(dict):
|
||||
|
||||
def __getitem__(self, key):
|
||||
value, expiry_time = super().__getitem__(key)
|
||||
# 如果元素已过期,则从字典中删除该元素并抛出 KeyError 异常
|
||||
if time.monotonic() > expiry_time:
|
||||
if datetime.now() > expiry_time:
|
||||
del self[key]
|
||||
raise KeyError("expired {}".format(key))
|
||||
self.__setitem__(key, value)
|
||||
|
||||
Reference in New Issue
Block a user