コード例 #1
0
ファイル: manager.py プロジェクト: grow/grow
def start(pod, host=None, port=None, open_browser=False, debug=False,
          preprocess=True, update_check=False):
    main_observer, podspec_observer = file_watchers.create_dev_server_observers(pod)
    if preprocess:
        thread = threading.Thread(target=pod.preprocess, kwargs={'build': False})
        thread.setDaemon(True)
        thread.start()
    port = 8080 if port is None else int(port)
    host = 'localhost' if host is None else host
    patch_broken_pipe_error()
    # Not safe for multi-pod serving env.
    CallbackHTTPServer.pod = pod
    CallbackHTTPServer.open_browser = open_browser
    CallbackHTTPServer.update_check = update_check
    serving.ThreadedWSGIServer = CallbackHTTPServer
    app = main_lib.create_wsgi_app(pod, host, port, debug=debug)
    serving._log = lambda *args, **kwargs: ''
    handler = main_lib.RequestHandler
    num_tries = 0
    done = False

    while num_tries < NUM_TRIES and not done:
        try:
            app.app.port = port
            serving.run_simple(host, port, app, request_handler=handler, threaded=True)
            done = True
        except socket.error as e:
            # if any(x in str(e) for x in ('Errno 48', 'Errno 98')):
            if 'Errno 48' in str(e):
                num_tries += 1
                port += 1
            else:
                # Clean up the file watchers.
                main_observer.stop()
                podspec_observer.stop()

                raise e
        finally:
            if done:
                # Clean up the file watchers.
                main_observer.stop()
                podspec_observer.stop()

                # Ensure ctrl+c works no matter what.
                # https://github.com/grow/grow/issues/149
                os._exit(0)

    text = 'Unable to find a port for the server (tried {}).'
    pod.logger.error(text.format(port))
    sys.exit(-1)
コード例 #2
0
ファイル: manager.py プロジェクト: cdhermann/grow
def start(pod, host=None, port=None, open_browser=False, debug=False,
          preprocess=True, update_check=False):
    main_observer, podspec_observer = file_watchers.create_dev_server_observers(pod)
    if preprocess:
        thread = threading.Thread(target=pod.preprocess, kwargs={'build': False})
        thread.setDaemon(True)
        thread.start()
    port = 8080 if port is None else int(port)
    host = 'localhost' if host is None else host
    patch_broken_pipe_error()
    # Not safe for multi-pod serving env.
    CallbackHTTPServer.pod = pod
    CallbackHTTPServer.open_browser = open_browser
    CallbackHTTPServer.update_check = update_check
    serving.ThreadedWSGIServer = CallbackHTTPServer
    app = main_lib.create_wsgi_app(pod, host, port, debug=debug)
    serving._log = lambda *args, **kwargs: ''
    handler = main_lib.RequestHandler
    num_tries = 0
    done = False

    while num_tries < NUM_TRIES and not done:
        try:
            app.app.port = port
            serving.run_simple(host, port, app, request_handler=handler, threaded=True)
            done = True
        except socket.error as e:
            # if any(x in str(e) for x in ('Errno 48', 'Errno 98')):
            if 'Errno 48' in str(e):
                num_tries += 1
                port += 1
            else:
                # Clean up the file watchers.
                main_observer.stop()
                podspec_observer.stop()

                raise e
        finally:
            if done:
                if pod.podcache.is_dirty:
                    pod.podcache.write()

                # Clean up the file watchers.
                main_observer.stop()
                podspec_observer.stop()
                return

    text = 'Unable to find a port for the server (tried {}).'
    pod.logger.error(text.format(port))
    sys.exit(-1)
コード例 #3
0
def start(pod,
          host=None,
          port=None,
          open_browser=False,
          debug=False,
          preprocess=True,
          update_check=False):
    observer, podspec_observer = file_watchers.create_dev_server_observers(pod)
    if preprocess:
        thread = threading.Thread(target=pod.preprocess,
                                  kwargs={'build': False})
        thread.setDaemon(True)
        thread.start()
    port = 8080 if port is None else int(port)
    host = 'localhost' if host is None else host
    patch_broken_pipe_error()
    # Not safe for multi-pod serving env.
    CallbackHTTPServer.pod = pod
    CallbackHTTPServer.open_browser = open_browser
    CallbackHTTPServer.update_check = update_check
    serving.ThreadedWSGIServer = CallbackHTTPServer
    app = main_lib.create_wsgi_app(pod, debug=debug)
    serving._log = lambda *args, **kwargs: ''
    handler = main_lib.RequestHandler
    num_tries = 0
    done = False
    while num_tries < NUM_TRIES and not done:
        try:
            serving.run_simple(host,
                               port,
                               app,
                               request_handler=handler,
                               threaded=True)
            done = True
        except socket.error as e:
            if 'Errno 48' in str(e):
                num_tries += 1
                port += 1
            else:
                raise e
        finally:
            # Ensure ctrl+c works no matter what.
            # https://github.com/grow/grow/issues/149
            if done:
                os._exit(0)
    text = 'Unable to find a port for the server (tried {}).'
    pod.logger.error(text.format(port))
    sys.exit(-1)
コード例 #4
0
ファイル: manager.py プロジェクト: Yzupnick/grow
def start(pod, host=None, port=None, open_browser=False, debug=False,
          preprocess=True, update_check=False):
    observer, podspec_observer = file_watchers.create_dev_server_observers(pod)
    if preprocess:
        # Run preprocessors for the first time in a thread.
        reactor.callInThread(pod.preprocess, build=False)
    port = 8080 if port is None else int(port)
    host = 'localhost' if host is None else host
    port = find_port_and_start_server(pod, host, port, debug)
    pod.env.port = port
    pod.load()
    url = print_server_ready_message(pod, host, port)
    if open_browser:
        start_browser(url)
    shutdown_func = lambda *args: shutdown(pod)
    reactor.addSystemEventTrigger('during', 'shutdown', shutdown_func)
    if update_check:
        reactor.callInThread(sdk_utils.check_for_sdk_updates, True)
    reactor.run()