7 from bottle import thread # portable import
9 from m_librarian.db import open_db
10 import m_librarian.web.app # noqa: F401 imported but unused
11 from m_librarian.web.server import run_server
12 from m_librarian.web.utils import get_lock, close_lock, get_open_port
15 def start_browser(port):
16 time.sleep(1) # A small timeout to allow the main thread to run the server
17 webbrowser.open_new('http://localhost:%d/' % port)
20 if __name__ == '__main__':
21 parser = argparse.ArgumentParser(description='Init')
22 parser.add_argument('-p', '--port', help='HTTP server port')
23 args = parser.parse_args()
28 port = get_open_port()
30 lock_file, old_port = get_lock(port)
33 thread.start_new_thread(start_browser, (port,))
36 else: # Another instance of the program is being run at a different port
37 start_browser(old_port)