def is_locked(dbPath): lockfile_path = get_lockfile_path(dbPath) lockfile = QtCore.QLockFile(str(lockfile_path)) if lockfile.tryLock(100): return False return True
def run_with_lockfile(dbPath: str): from PyQt5 import QtCore, QtWidgets dbPath = Path(dbPath).expanduser().absolute() lockfile_path = get_lockfile_path(dbPath) print(lockfile_path) lockfile = QtCore.QLockFile(str(lockfile_path)) if lockfile.tryLock(100): app = QtGui.QApplication([]) # what is the right way to create a logger for this? # log_win = plottrlog.setupLogging(level=logging.DEBUG) plottrlog.enableStreamHandler(False) # no log handler at this point win = inspectr.inspectr(dbPath=dbPath) win.show() if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): app.exec() return raise RuntimeWarning("plottr instance already open for this database!" ) # inspectr already running