Example #1
0
    def run_server(reporting_queue):
      def report_launch(actual_port):
        reporting_queue.put(
          'Launching server with pid %d at http://localhost:%d' % (os.getpid(), actual_port))

      def done_reporting():
        reporting_queue.put(DONE)

      try:
        # We mustn't block in the child, because the multiprocessing module enforces that the
        # parent either kills or joins to it. Instead we fork a grandchild that inherits the queue
        # but is allowed to block indefinitely on the server loop.
        if not os.fork():
          # Child process.
          info_dir = RunInfo.dir(self.context.config)
          # If these are specified explicitly in the config, use those. Otherwise
          # they will be None, and we'll use the ones baked into this package.
          template_dir = self.context.config.get('reporting', 'reports_template_dir')
          assets_dir = self.context.config.get('reporting', 'reports_assets_dir')
          settings = ReportingServer.Settings(info_dir=info_dir, template_dir=template_dir,
                                              assets_dir=assets_dir, root=get_buildroot(),
                                              allowed_clients=self.context.options.allowed_clients)
          server = ReportingServer(self.context.options.port, settings)
          actual_port = server.server_port()
          ReportingServerManager.save_current_server_port(actual_port)
          report_launch(actual_port)
          done_reporting()
          # Block forever here.
          server.start()
      except socket.error:
        done_reporting()
        raise
Example #2
0
        def run_server(reporting_queue):
            (port, pidfile) = get_port_and_pidfile(self.context)

            def write_pidfile():
                safe_mkdir(os.path.dirname(pidfile))
                with open(pidfile, 'w') as outfile:
                    outfile.write(str(os.getpid()))

            def report_launch():
                reporting_queue.put(
                    'Launching server with pid %d at http://localhost:%d' %
                    (os.getpid(), port))
                show_latest_run_msg()

            def show_latest_run_msg():
                url = 'http://localhost:%d/run/latest' % port
                try:
                    from colors import magenta
                    url = magenta(url)
                except ImportError:
                    pass
                reporting_queue.put('Automatically see latest run at %s' % url)

            def done_reporting():
                reporting_queue.put(DONE)

            try:
                # We mustn't block in the child, because the multiprocessing module enforces that the
                # parent either kills or joins to it. Instead we fork a grandchild that inherits the queue
                # but is allowed to block indefinitely on the server loop.
                if not os.fork():
                    # Child process.
                    info_dir = self.context.config.getdefault('info_dir')
                    template_dir = self.context.config.get(
                        'reporting', 'reports_template_dir')
                    assets_dir = self.context.config.get(
                        'reporting', 'reports_assets_dir')
                    settings = ReportingServer.Settings(
                        info_dir=info_dir,
                        template_dir=template_dir,
                        assets_dir=assets_dir,
                        root=get_buildroot(),
                        allowed_clients=self.context.options.allowed_clients)
                    server = ReportingServer(port, settings)
                    # Block forever here.
                    server.start(run_before_blocking=[
                        write_pidfile, report_launch, done_reporting
                    ])
            except socket.error, e:
                if e.errno == errno.EADDRINUSE:
                    reporting_queue.put(
                        'Server already running at http://localhost:%d' % port)
                    show_latest_run_msg()
                    done_reporting()
                    return
                else:
                    done_reporting()
                    raise
Example #3
0
    def run_server(reporting_queue):
      (port, pidfile) = get_port_and_pidfile(self.context)
      def write_pidfile():
        safe_mkdir(os.path.dirname(pidfile))
        with open(pidfile, 'w') as outfile:
          outfile.write(str(os.getpid()))

      def report_launch():
        reporting_queue.put(
          'Launching server with pid %d at http://localhost:%d' % (os.getpid(), port))
        show_latest_run_msg()

      def show_latest_run_msg():
        url = 'http://localhost:%d/run/latest' % port
        try:
          from colors import magenta
          url = magenta(url)
        except ImportError:
          pass
        reporting_queue.put('Automatically see latest run at %s' % url)

      def done_reporting():
        reporting_queue.put(DONE)

      try:
        # We mustn't block in the child, because the multiprocessing module enforces that the
        # parent either kills or joins to it. Instead we fork a grandchild that inherits the queue
        # but is allowed to block indefinitely on the server loop.
        if not os.fork():
          # Child process.
          info_dir = self.context.config.getdefault('info_dir')
          template_dir = self.context.config.get('reporting', 'reports_template_dir')
          assets_dir = self.context.config.get('reporting', 'reports_assets_dir')
          settings = ReportingServer.Settings(info_dir=info_dir, template_dir=template_dir,
                                              assets_dir=assets_dir, root=get_buildroot(),
                                              allowed_clients=self.context.options.allowed_clients)
          server = ReportingServer(port, settings)
          # Block forever here.
          server.start(run_before_blocking=[write_pidfile, report_launch, done_reporting])
      except socket.error, e:
        if e.errno == errno.EADDRINUSE:
          reporting_queue.put('Server already running at http://localhost:%d' % port)
          show_latest_run_msg()
          done_reporting()
          return
        else:
          done_reporting()
          raise
Example #4
0
    def run_server(reporting_queue):
      def report_launch(actual_port):
        reporting_queue.put(
          'Launching server with pid %d at http://localhost:%d' % (os.getpid(), actual_port))

      def done_reporting():
        reporting_queue.put(DONE)

      try:
        # We mustn't block in the child, because the multiprocessing module enforces that the
        # parent either kills or joins to it. Instead we fork a grandchild that inherits the queue
        # but is allowed to block indefinitely on the server loop.
        if not os.fork():
          # Child process.
          info_dir = RunInfo.dir(self.context.config)
          # If these are specified explicitly in the config, use those. Otherwise
          # they will be None, and we'll use the ones baked into this package.
          template_dir = self.context.config.get('reporting', 'reports_template_dir')
          assets_dir = self.context.config.get('reporting', 'reports_assets_dir')
          settings = ReportingServer.Settings(info_dir=info_dir, template_dir=template_dir,
                                              assets_dir=assets_dir, root=get_buildroot(),
                                              allowed_clients=self.context.options.allowed_clients)
          server = ReportingServer(self.context.options.port, settings)
          actual_port = server.server_port()
          ReportingServerManager.save_current_server_port(actual_port)
          report_launch(actual_port)
          done_reporting()
          # Block forever here.
          server.start()
      except socket.error:
        done_reporting()
        raise