X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=scripts%2Fml-web.py;h=c93b5fd88c2243a4d923d2a795065592e605b417;hb=682b34d490bb1a81e2e17a187f46eb188ae4c455;hp=bccac810821833844272fd2bf90eae29afbc73ee;hpb=c36e520339e5c0043fa6861f43ff5915999eb980;p=m_librarian.git diff --git a/scripts/ml-web.py b/scripts/ml-web.py index bccac81..c93b5fd 100755 --- a/scripts/ml-web.py +++ b/scripts/ml-web.py @@ -7,9 +7,9 @@ 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 +import m_librarian.web.app # noqa: F401 imported but unused def start_browser(port): @@ -18,7 +18,7 @@ def start_browser(port): if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Init') + parser = argparse.ArgumentParser(description='m_Librarin web interface') parser.add_argument('-p', '--port', help='HTTP server port') args = parser.parse_args() @@ -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)