fix dblock

This commit is contained in:
jxxghp 2023-10-18 19:42:46 +08:00
parent 3d34c26731
commit 897369d300
2 changed files with 8 additions and 5 deletions

View File

@ -1,8 +1,13 @@
import threading
from sqlalchemy import create_engine, QueuePool
from sqlalchemy.orm import sessionmaker, Session, scoped_session
from app.core.config import settings
# 数据库锁
DBLock = threading.Lock()
# 数据库引擎
Engine = create_engine(f"sqlite:///{settings.CONFIG_PATH}/user.db",
pool_pre_ping=True,
@ -44,4 +49,5 @@ class DbOper:
if db:
self._db = db
else:
self._db = ScopedSession()
with DBLock:
self._db = ScopedSession()

View File

@ -3,10 +3,7 @@ from typing import Any, Self, List
from sqlalchemy.orm import as_declarative, declared_attr, Session
from app.db import ScopedSession
# 数据库锁
DBLock = threading.Lock()
from app.db import ScopedSession, DBLock
def db_persist(func):