Beispiel #1
0
    def _spawn_nailgun_server(self, workunit):
        self.context.log.debug("No ng server found, spawning...")

        with _safe_open(self._ng_out, "w"):
            pass  # truncate

        pid = os.fork()
        if pid != 0:
            # In the parent tine - block on ng being up for connections
            return self._await_nailgun_server(workunit)

        # NOTE: Don't use self.context.log or self.context.new_workunit here.
        # They use threadlocal state, which interacts poorly with fork().
        os.setsid()
        in_fd = open("/dev/null", "w")
        out_fd = safe_open(self._ng_out, "w")
        err_fd = safe_open(self._ng_err, "w")
        args = ["java"]
        if self._ng_server_args:
            args.extend(self._ng_server_args)
        args.append(NailgunTask.PANTS_NG_ARG)
        args.append(self._identifier_arg)
        ng_classpath = os.pathsep.join(binary_util.profile_classpath(self._nailgun_profile))
        args.extend(["-cp", ng_classpath, "com.martiansoftware.nailgun.NGServer", ":0"])
        s = " ".join(args)

        with binary_util.safe_classpath():
            subprocess.Popen(args, stdin=in_fd, stdout=out_fd, stderr=err_fd, close_fds=True, cwd=get_buildroot())
            # Prevents finally blocks being executed, unlike sys.exit(). We don't want to execute finally
            # blocks because we might, e.g., clean up tempfiles that the parent still needs.
            os._exit(0)
Beispiel #2
0
    def _spawn_nailgun_server(self, workunit):
        log.info('No ng server found, spawning...')

        with _safe_open(self._ng_out, 'w'):
            pass  # truncate

        if os.path.exists(self._pidfile):
            os.remove(
                self._pidfile)  # So we know when the child has written it.
        pid = os.fork()
        if pid != 0:
            # In the parent tine - block on ng being up for connections
            return self._await_nailgun_server(workunit)

        os.setsid()
        in_fd = open('/dev/null', 'w')
        out_fd = safe_open(self._ng_out, 'w')
        err_fd = safe_open(self._ng_err, 'w')

        args = ['java']
        if self._ng_server_args:
            args.extend(self._ng_server_args)
        args.append(NailgunTask.PANTS_NG_ARG)
        args.append(NailgunTask.create_pidfile_arg(self._pidfile))
        ng_classpath = os.pathsep.join(
            binary_util.profile_classpath(
                self._nailgun_profile,
                workunit_factory=self.context.new_workunit))
        args.extend([
            '-cp', ng_classpath, 'com.martiansoftware.nailgun.NGServer', ':0'
        ])
        log.debug('Executing: %s' % ' '.join(args))

        with binary_util.safe_classpath(logger=log.warn):
            process = subprocess.Popen(args,
                                       stdin=in_fd,
                                       stdout=out_fd,
                                       stderr=err_fd,
                                       close_fds=True,
                                       cwd=get_buildroot())
            with _safe_open(self._pidfile, 'w') as pidfile:
                pidfile.write('%d' % process.pid)
            log.debug('Spawned ng server @ %d' % process.pid)
            # Prevents finally blocks being executed, unlike sys.exit(). We don't want to execute finally
            # blocks because we might, e.g., clean up tempfiles that the parent still needs.
            os._exit(0)
Beispiel #3
0
  def _spawn_nailgun_server(self, workunit):
    log.info('No ng server found, spawning...')

    with _safe_open(self._ng_out, 'w'):
      pass # truncate

    if os.path.exists(self._pidfile):
      os.remove(self._pidfile)  # So we know when the child has written it.
    pid = os.fork()
    if pid != 0:
      # In the parent tine - block on ng being up for connections
      return self._await_nailgun_server(workunit)

    os.setsid()
    in_fd = open('/dev/null', 'w')
    out_fd = safe_open(self._ng_out, 'w')
    err_fd = safe_open(self._ng_err, 'w')

    args = ['java']
    if self._ng_server_args:
      args.extend(self._ng_server_args)
    args.append(NailgunTask.PANTS_NG_ARG)
    args.append(NailgunTask.create_pidfile_arg(self._pidfile))
    ng_classpath = os.pathsep.join(binary_util.profile_classpath(self._nailgun_profile,
      workunit_factory=self.context.new_workunit))
    args.extend(['-cp', ng_classpath, 'com.martiansoftware.nailgun.NGServer', ':0'])
    log.debug('Executing: %s' % ' '.join(args))

    with binary_util.safe_classpath(logger=log.warn):
      process = subprocess.Popen(
        args,
        stdin=in_fd,
        stdout=out_fd,
        stderr=err_fd,
        close_fds=True,
        cwd=get_buildroot()
      )
      with _safe_open(self._pidfile, 'w') as pidfile:
        pidfile.write('%d' % process.pid)
      log.debug('Spawned ng server @ %d' % process.pid)
      # Prevents finally blocks being executed, unlike sys.exit(). We don't want to execute finally
      # blocks because we might, e.g., clean up tempfiles that the parent still needs.
      os._exit(0)
Beispiel #4
0
  def _spawn_nailgun_server(self, workunit):
    self.context.log.debug('No ng server found, spawning...')

    with _safe_open(self._ng_out, 'w'):
      pass  # truncate

    ng_classpath = os.pathsep.join(
      self._bootstrap_utils.get_jvm_build_tools_classpath(self._nailgun_bootstrap_key))

    pid = os.fork()
    if pid != 0:
      # In the parent tine - block on ng being up for connections
      return self._await_nailgun_server(workunit)

    # NOTE: Don't use self.context.log or self.context.new_workunit here.
    # They use threadlocal state, which interacts poorly with fork().
    os.setsid()
    in_fd = open('/dev/null', 'w')
    out_fd = safe_open(self._ng_out, 'w')
    err_fd = safe_open(self._ng_err, 'w')
    args = ['java']
    if self._ng_server_args:
      args.extend(self._ng_server_args)
    args.append(NailgunTask.PANTS_NG_ARG)
    args.append(self._identifier_arg)
    args.extend(['-cp', ng_classpath, 'com.martiansoftware.nailgun.NGServer', ':0'])
    s = ' '.join(args)

    with binary_util.safe_classpath():
      subprocess.Popen(
        args,
        stdin=in_fd,
        stdout=out_fd,
        stderr=err_fd,
        close_fds=True,
        cwd=get_buildroot()
      )
      # Prevents finally blocks being executed, unlike sys.exit(). We don't want to execute finally
      # blocks because we might, e.g., clean up tempfiles that the parent still needs.
      os._exit(0)