code: def launch(self):
      
      cmd = self._construct_cmd((self._watchman_path, 'get-pid'),
                                state_file=self._state_file,
                                sock_file=self._sock_file,
                                pid_file=self._pid_file,
                                log_file=self._log_file,
                                log_level=str(self._log_level))
      self._logger.debug('watchman cmd is: {}'.format(' '.join(cmd)))
      self._maybe_init_metadata()
  
      # Watchman is launched via its cli. By running the 'get-pid' command on the client we implicitly
      # launch the Watchman daemon. This approach is somewhat error-prone - in some cases the client
      # can successfully trigger the launch of the Watchman daemon, but fail to return successfully
      # for the 'get-pid' result due to server <-> daemon socket issues - these can look like:
      #
      #   2016-04-01T17:31:23,820: [cli] unable to talk to your watchman
      #                                  on .../watchman.sock! (Permission denied)
      #
      # This results in a subprocess execution failure and leaves us with no pid information to write
      # to the metadata directory - while in reality a Watchman daemon is actually running but now
      # untracked. To safeguard against this, we retry the (idempotent) 'get-pid' command a few times
      # to give the server-side socket setup a few chances to quiesce before potentially orphaning it.
  
      get_output = functools.partial(self.get_subprocess_output, cmd)
      output = retry_on_exception(get_output, 3, (ProcessManager.ExecutionError,), lambda n: n * .5)
  
      # Parse the watchman PID from the cli output.
      pid = self._parse_pid_from_output(output)
  
      # Write the process metadata to disk.
      self.write_pid(pid)
      self.write_socket(self._sock_file)
docs: Launch and synchronously write metadata.
  
      This is possible due to watchman's built-in async server startup - no double-forking required.