Session acquisitiong logging
This commit is contained in:
parent
47f53428f6
commit
75b814e26c
@ -1,7 +1,9 @@
|
||||
import inspect
|
||||
import os
|
||||
import sqlalchemy
|
||||
|
||||
from config import Config
|
||||
from contextlib import contextmanager
|
||||
from sqlalchemy.orm import (sessionmaker, scoped_session)
|
||||
|
||||
MM_ENV = os.environ.get('MM_ENV', 'PRODUCTION')
|
||||
@ -35,4 +37,20 @@ engine = sqlalchemy.create_engine(
|
||||
pool_pre_ping=True
|
||||
)
|
||||
|
||||
Session = scoped_session(sessionmaker(bind=engine))
|
||||
|
||||
# Session = scoped_session(sessionmaker(bind=engine))
|
||||
@contextmanager
|
||||
def Session():
|
||||
frame = inspect.stack()[2]
|
||||
file = frame.filename
|
||||
function = frame.function
|
||||
lineno = frame.lineno
|
||||
print(f"Session acquired, {file=}, {function=}, {lineno=}")
|
||||
# yield scoped_session(sessionmaker(bind=engine))
|
||||
Session = scoped_session(sessionmaker(bind=engine))
|
||||
yield Session
|
||||
print(" Session released")
|
||||
Session.commit()
|
||||
print(" Session committed")
|
||||
Session.close()
|
||||
print(" Session closed")
|
||||
|
||||
@ -518,6 +518,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
DEBUG("musicmuster.play_next(): no next track selected", True)
|
||||
return
|
||||
|
||||
self.kae()
|
||||
|
||||
with Session() as session:
|
||||
# If there's currently a track playing, fade it.
|
||||
self.stop_playing(fade=True)
|
||||
@ -994,7 +996,6 @@ class SelectPlaylistDialog(QDialog):
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
Base.metadata.create_all(dbconfig.engine)
|
||||
Session = dbconfig.Session
|
||||
app = QApplication(sys.argv)
|
||||
win = Window()
|
||||
win.show()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user