How to use the pywatchman.CLIProcessTransport function in pywatchman

To help you get started, we’ve selected a few pywatchman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pantsbuild / pants / src / python / pants / pantsd / watchman_client.py View on Github external
def stream_query(self, commands):
    """A generator of watchman events that allows queries to be pipelined and multiplexed. This
    continuously yields unilateral events and subscribe events, or None until an error condition
    or non-unilateral event (aside from subscribe) is received, at which point the generator
    ceases.

    The generator will yield None on socket timeouts unless the client's timeout has been set to
    None, in which case it will block indefinitely waiting on responses.

    :param iterable commands: An iterable of commands to send to watchman - e.g. one or more
                              subscribe commands.
    """
    # The CLI transport does not support pipelining.
    if self.transport is pywatchman.CLIProcessTransport:
      raise NotImplementedError()

    cmd_buf = deque(command for command in reversed(commands))
    self._connect()

    while 1:
      # Interleave sends and receives to avoid bi-directional communication issues.
      if cmd_buf:
        item = cmd_buf.pop()
        try:
          self.sendConn.send(item)
        except pywatchman.SocketTimeout:
          cmd_buf.append(item)
          yield

      try: