X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=scripts%2Fml-web.py;h=0387bc67088abab00d464681cae3f5afd70e6968;hb=ce323cc1847cdb57a6fc6df2c685e68fd76be522;hp=f5a579e006718b3be33d1ea85ca3856a4e00851a;hpb=2d76928b93c208d27f942b9a9eb649df1d5b2192;p=m_librarian.git diff --git a/scripts/ml-web.py b/scripts/ml-web.py index f5a579e..0387bc6 100755 --- a/scripts/ml-web.py +++ b/scripts/ml-web.py @@ -6,9 +6,10 @@ import webbrowser from bottle import thread # portable import +from m_librarian.db import open_db import m_librarian.web.app # noqa: F401 imported but unused from m_librarian.web.server import run_server -from m_librarian.web.utils import get_open_port +from m_librarian.web.utils import get_lock, close_lock, get_open_port def start_browser(port): @@ -26,5 +27,11 @@ if __name__ == '__main__': else: port = get_open_port() - thread.start_new_thread(start_browser, (port,)) - run_server(port=port) + lock_file, old_port = get_lock(port) + if lock_file: + open_db() + thread.start_new_thread(start_browser, (port,)) + run_server(port=port) + close_lock(lock_file) + else: # Another instance of the program is being run at a different port + start_browser(old_port)