当前位置: 首页>>代码示例>>Python>>正文


Python NailgunProtocol.write_chunk方法代码示例

本文整理汇总了Python中pants.java.nailgun_protocol.NailgunProtocol.write_chunk方法的典型用法代码示例。如果您正苦于以下问题:Python NailgunProtocol.write_chunk方法的具体用法?Python NailgunProtocol.write_chunk怎么用?Python NailgunProtocol.write_chunk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pants.java.nailgun_protocol.NailgunProtocol的用法示例。


在下文中一共展示了NailgunProtocol.write_chunk方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_fork_child

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def post_fork_child(self):
    """Post-fork child process callback executed via ProcessManager.daemonize()."""
    # Set the Exiter exception hook post-fork so as not to affect the pantsd processes exception
    # hook with socket-specific behavior.
    self._exiter.set_except_hook()

    # Set context in the process title.
    set_process_title('pantsd-runner [{}]'.format(' '.join(self._args)))

    # Broadcast our pid to the remote client so they can send us signals (i.e. SIGINT).
    NailgunProtocol.write_chunk(self._socket, ChunkType.PID, bytes(os.getpid()))

    # Setup a SIGINT signal handler.
    self._setup_sigint_handler()

    # Invoke a Pants run with stdio redirected.
    with self._nailgunned_stdio(self._socket):
      try:
        # Clean global state.
        clean_global_runtime_state(reset_subsystem=True)

        # Re-raise any deferred exceptions, if present.
        self._raise_deferred_exc()

        # Otherwise, conduct a normal run.
        LocalPantsRunner(self._exiter, self._args, self._env, self._graph_helper).run()
      except KeyboardInterrupt:
        self._exiter.exit(1, msg='Interrupted by user.\n')
      except Exception:
        self._exiter.handle_unhandled_exception(add_newline=True)
      else:
        self._exiter.exit(0)
开发者ID:UnrememberMe,项目名称:pants,代码行数:34,代码来源:daemon_pants_runner.py

示例2: run

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def run(self):
    while self._in_fds and not self.is_stopped:
      readable, _, errored = select.select(self._in_fds, [], self._in_fds, self._select_timeout)

      if readable:
        for fileno in readable:
          data = os.read(fileno, self._buf_size)

          if not data:
            # We've reached EOF.
            try:
              if self._chunk_eof_type is not None:
                NailgunProtocol.write_chunk(self._socket, self._chunk_eof_type)
            finally:
              try:
                os.close(fileno)
              finally:
                self._in_fds.remove(fileno)
          else:
            NailgunProtocol.write_chunk(
              self._socket,
              self._fileno_chunk_type_map[fileno],
              data
            )

      if errored:
        for fileno in errored:
          self._in_fds.remove(fileno)
开发者ID:baroquebobcat,项目名称:pants,代码行数:30,代码来源:nailgun_io.py

示例3: write

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
 def write(self, payload):
   try:
     NailgunProtocol.write_chunk(self._socket, self._chunk_type, payload)
   except IOError as e:
     # If the remote client disconnects and we try to perform a write (e.g. socket.send/sendall),
     # an 'error: [Errno 32] Broken pipe' exception can be thrown. Setting mask_broken_pipe=True
     # safeguards against this case (which is unexpected for most writers of sys.stdout etc) so
     # that we don't awkwardly interrupt the runtime by throwing this exception on writes to
     # stdout/stderr.
     if e.errno == errno.EPIPE and not self._mask_broken_pipe:
       raise
开发者ID:grimreaper,项目名称:pants,代码行数:13,代码来源:nailgun_io.py

示例4: test_read_and_write_chunk

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def test_read_and_write_chunk(self):
    # Write a command chunk to the server socket.
    NailgunProtocol.write_chunk(self.server_sock, ChunkType.COMMAND, self.TEST_COMMAND)

    # Read the chunk from the client socket.
    chunk_type, payload = NailgunProtocol.read_chunk(self.client_sock)

    self.assertEqual(
      (chunk_type, payload),
      (ChunkType.COMMAND, self.TEST_COMMAND)
    )
开发者ID:Gointer,项目名称:pants,代码行数:13,代码来源:test_nailgun_protocol.py

示例5: test_iter_chunks

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def test_iter_chunks(self):
    expected_chunks = [
      (ChunkType.COMMAND, self.TEST_COMMAND),
      (ChunkType.STDOUT, self.TEST_OUTPUT),
      (ChunkType.STDERR, self.TEST_OUTPUT),
      (ChunkType.EXIT, self.EMPTY_PAYLOAD)
      # N.B. without an EXIT chunk here (or socket failure), this test will deadlock in iter_chunks.
    ]

    for chunk_type, payload in expected_chunks:
      NailgunProtocol.write_chunk(self.server_sock, chunk_type, payload)

    for i, chunk in enumerate(NailgunProtocol.iter_chunks(self.client_sock)):
      self.assertEqual(chunk, expected_chunks[i])
开发者ID:Gointer,项目名称:pants,代码行数:16,代码来源:test_nailgun_protocol.py

示例6: exit

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def exit(self, result=0, msg=None):
    """Exit the runtime."""
    try:
      # Write a final message to stderr if present.
      if msg:
        NailgunProtocol.write_chunk(self._socket, ChunkType.STDERR, msg)

      # Send an Exit chunk with the result.
      NailgunProtocol.write_chunk(self._socket, ChunkType.EXIT, str(result).encode('ascii'))

      # Shutdown the connected socket.
      self._shutdown_socket()
    finally:
      # N.B. Assuming a fork()'d child, os._exit(0) here to avoid the routine sys.exit() behavior.
      os._exit(0)
开发者ID:UnrememberMe,项目名称:pants,代码行数:17,代码来源:daemon_pants_runner.py

示例7: exit

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def exit(self, result=0, msg=None):
    """Exit the runtime."""
    try:
      # Write a final message to stderr if present.
      if msg:
        NailgunProtocol.write_chunk(self._socket, ChunkType.STDERR, msg)

      # Send an Exit chunk with the result.
      NailgunProtocol.write_chunk(self._socket, ChunkType.EXIT, str(result).encode('ascii'))

      # Shutdown the connected socket.
      self._shutdown_socket()
    finally:
      # N.B. Assuming a fork()'d child, cause os._exit to be called here to avoid the routine
      # sys.exit behavior (via `pants.util.contextutil.hard_exit_handler()`).
      raise HardSystemExit()
开发者ID:pombredanne,项目名称:pants,代码行数:18,代码来源:daemon_pants_runner.py

示例8: run

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def run(self):
    while not self.is_stopped:
      readable, _, errored = select.select([self._stdin], [], [self._stdin], self._select_timeout)

      if self._stdin in errored:
        self.stop()
        return

      if not self.is_stopped and self._stdin in readable:
        data = os.read(self._stdin.fileno(), self._buf_size)

        if not self.is_stopped:
          if data:
            NailgunProtocol.write_chunk(self._socket, ChunkType.STDIN, data)
          else:
            NailgunProtocol.write_chunk(self._socket, ChunkType.STDIN_EOF)
            try:
              self._socket.shutdown(socket.SHUT_WR)  # Shutdown socket sends.
            except socket.error:  # Can happen if response is quick.
              pass
            finally:
              self.stop()
开发者ID:grimreaper,项目名称:pants,代码行数:24,代码来源:nailgun_io.py

示例9: test_process_session_bad_chunk

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def test_process_session_bad_chunk(self):
    NailgunProtocol.write_chunk(self.server_sock, ChunkType.PID, b'31337')
    NailgunProtocol.write_chunk(self.server_sock, ChunkType.START_READING_INPUT)
    NailgunProtocol.write_chunk(self.server_sock, self.BAD_CHUNK_TYPE, '')

    with self.assertRaises(NailgunClientSession.ProtocolError):
      self.nailgun_client_session._process_session()

    self.mock_stdin_reader.start.assert_called_once_with()
    self.mock_stdin_reader.stop.assert_called_once_with()
开发者ID:baroquebobcat,项目名称:pants,代码行数:12,代码来源:test_nailgun_client.py

示例10: test_send_and_parse_request_bad_chunktype

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def test_send_and_parse_request_bad_chunktype(self):
    INVALID_CHUNK_TYPE = b';'
    NailgunProtocol.write_chunk(self.client_sock, INVALID_CHUNK_TYPE, '1729')

    with self.assertRaises(NailgunProtocol.ProtocolError):
      NailgunProtocol.parse_request(self.server_sock)
开发者ID:Gointer,项目名称:pants,代码行数:8,代码来源:test_nailgun_protocol.py

示例11: test_process_session

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
 def test_process_session(self):
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.PID, b'31337')
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.START_READING_INPUT)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDOUT, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDERR, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDERR, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDOUT, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDERR, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.EXIT, b'1729')
   self.assertEquals(self.nailgun_client_session._process_session(), 1729)
   self.assertEquals(self.fake_stdout.content, self.TEST_PAYLOAD * 2)
   self.assertEquals(self.fake_stderr.content, self.TEST_PAYLOAD * 3)
   self.mock_stdin_reader.start.assert_called_once_with()
   self.mock_stdin_reader.stop.assert_called_once_with()
   self.assertEquals(self.nailgun_client_session.remote_pid, 31337)
开发者ID:baroquebobcat,项目名称:pants,代码行数:17,代码来源:test_nailgun_client.py

示例12: handle_error

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
 def handle_error(self, exc=None):
   """Error handler for failed calls to handle()."""
   if exc:
     NailgunProtocol.write_chunk(self.request, ChunkType.STDERR, traceback.format_exc())
   NailgunProtocol.write_chunk(self.request, ChunkType.EXIT, '1')
开发者ID:CaitieM20,项目名称:pants,代码行数:7,代码来源:pailgun_server.py

示例13: test_process_session_bad_chunk

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
  def test_process_session_bad_chunk(self):
    NailgunProtocol.write_chunk(self.server_sock, self.BAD_CHUNK_TYPE, '')

    with self.assertRaises(NailgunClientSession.ProtocolError):
      self.nailgun_client_session._process_session()
开发者ID:megaserg,项目名称:pants,代码行数:7,代码来源:test_nailgun_client.py

示例14: test_process_session

# 需要导入模块: from pants.java.nailgun_protocol import NailgunProtocol [as 别名]
# 或者: from pants.java.nailgun_protocol.NailgunProtocol import write_chunk [as 别名]
 def test_process_session(self):
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDOUT, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDERR, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDERR, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDOUT, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.STDERR, self.TEST_PAYLOAD)
   NailgunProtocol.write_chunk(self.server_sock, ChunkType.EXIT, '1729')
   self.assertEquals(self.nailgun_client_session._process_session(), 1729)
   self.assertEquals(self.fake_stdout.content, self.TEST_PAYLOAD * 2)
   self.assertEquals(self.fake_stderr.content, self.TEST_PAYLOAD * 3)
开发者ID:megaserg,项目名称:pants,代码行数:12,代码来源:test_nailgun_client.py


注:本文中的pants.java.nailgun_protocol.NailgunProtocol.write_chunk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。