X-Git-Url: https://git.phdru.name/?p=m_librarian.git;a=blobdiff_plain;f=scripts%2Fml-web.py;h=0387bc67088abab00d464681cae3f5afd70e6968;hp=bccac810821833844272fd2bf90eae29afbc73ee;hb=0a6c338f3fb637c8d04a72aed92e809f61f9c2d2;hpb=18d73e91d3fef68fcc34b39f94f886434dbc85bc diff --git a/scripts/ml-web.py b/scripts/ml-web.py index bccac81..0387bc6 100755 --- a/scripts/ml-web.py +++ b/scripts/ml-web.py @@ -9,7 +9,7 @@ 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): @@ -27,6 +27,11 @@ if __name__ == '__main__': else: port = get_open_port() - open_db() - 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)