Find the watchman socket or raise.
190506
def get_watchman_sockpath(binpath='watchman'):
    
    path = os.getenv('WATCHMAN_SOCK')
    if path:
        return path

    cmd = [binpath, '--output-encoding=json', 'get-sockname']
    result = subprocess.check_output(cmd)
    result = json.loads(result)
    return result['sockname']
1037458
def run(self):
        """"""

        idle_watchers = []

        while True:
            try:
                if self._work_queue.empty() and len(idle_watchers) > 0:
                    for watcher in idle_watchers:
                        try:
                            watcher()
                        except: # pylint:disable=bare-except;We can't let one idle watcher failure impact any other watcher
                            self._logger.exception("Error inside queue idle watcher")

                    idle_watchers = []

                item = self._work_queue.get()

                # Handle special actions that are not RPCs
                if item is STOP_WORKER_ITEM:
                    return
                elif isinstance(item, MarkLocationItem):
                    item.callback()
                    continue
                elif isinstance(item, WaitIdleItem):
                    idle_watchers.append(item.callback)
                    continue
                elif not isinstance(item, WorkItem):
                    self._logger.error("Invalid item passed to WorkQueueThread: %s, ignoring", item)
                    continue

                self.direct_dispatch(item.arg, item.callback)

            except:  # pylint:disable=bare-except;We cannot let this background thread die until we are told to stop()
                self._logger.exception("Error inside background workqueue thread")
1122605
def _start_watching_blocks(self):
        '''
        
        '''
        if sum(map(len, (self.solid_watchers, self.block_watchers))) == 1:
            eth.filter('latest').watch(self._new_block)
923485
private String findSocketFile(int pid) {
        File f = new File(tmpdir, ".java_pid" + pid);
        if (!f.exists()) {
            return null;
        }
        return f.getPath();
    }
198156
def start(self):
        """"""
        if self.closed:
            raise ConnectionClosed()

        self.read_watcher.start()
        if self.write == self.buffered_write:
            self.write_watcher.start()
710855
function VogueClient(clientSocket, watcher) {
  this.socket = clientSocket;
  this.watcher = watcher;
  this.watchedFiles = {};
  clientSocket.on('watch', this.handleMessage.bind(this));
  clientSocket.on('disconnect', this.disconnect.bind(this));
}
1080710
void handleDisconnected() throws IOException {
		synchronized (this.asyncMutex) {
			if (socket != null) {
				socket.close();
			}
			this.socket = new Socket(server, port);
			this.in = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
			this.out = new BufferedWriter(new OutputStreamWriter(this.socket.getOutputStream()));
			
			this.listenThread = new SocketThread(this.in, this, this.resultParser, this.daemon);
			this.listenThread.start();
			if (lastWatch != null) { // restore watch if we had one.
				this.syncCommand(lastWatch, WatchObject.class);
			}
		}
		
	}
1244330
async def _upgrade_websocket(self, environ):
        """"""
        if self.upgraded:
            raise IOError('Socket has been upgraded already')
        if self.server._async['websocket'] is None:
            # the selected async mode does not support websocket
            return self.server._bad_request()
        ws = self.server._async['websocket'](self._websocket_handler)
        return await ws(environ)
850656
def watcher(self) -> Watcher:
        
        if not hasattr(self, "_watcher"):
            self._watcher = Watcher()
        return self._watcher
624740
private void doConnect(){
        task = new SocketDeamonTask();
        connectThread = new Thread(task);
        connectThread.setDaemon(true);
        connectThread.start();
    }
129226
def activate_watch(self, watch_id, params=None):
        
        if watch_id in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'watch_id'.")
        return self.transport.perform_request(
            "PUT", _make_path("_watcher", "watch", watch_id, "_activate"), params=params
        )
1198480
def watch_project(self, path):
    
    # TODO(kwlzn): Add a client.query(timeout=X) param to the upstream pywatchman project.
    try:
      return self.client.query('watch-project', os.path.realpath(path))
    finally:
      self._attempt_set_timeout(self._timeout)
8673
def socket(self, blocking=True):
        ''''''
        # If the socket is available, then yield it. Otherwise, yield nothing
        if self._socket_lock.acquire(blocking):
            try:
                yield self._socket
            finally:
                self._socket_lock.release()
1256469
private void pollUpstream() {
    if (!awaitingInner) {
      return;
    }

    boolean localDone = this.done;

    // Try to move the new item into the reframer
    InnerT newUpstreamItem = newItem.getAndSet(null);
    if (newUpstreamItem != null) {
      reframer.push(newUpstreamItem);
      // and reset the awaiting flag, if the item arrived or upstream closed
      awaitingInner = false;
    } else if (localDone) {
      awaitingInner = false;
    }
  }
1371218
def dispatch_sockets(self, timeout=None):
        """"""
        for sock in self.select_sockets(timeout=timeout):
            if sock is self.listener:
                listener = sock
                sock, addr = listener.accept()
                self.connected(sock)
            else:
                try:
                    sock.recv(1)
                except socket.error as exc:
                    if exc.errno != ECONNRESET:
                        raise
                self.disconnected(sock)
1304921
def _attempt_set_timeout(self, timeout):
    """"""
    try:
      self.client.setTimeout(timeout)
    except Exception:
      self._logger.debug('failed to set post-startup watchman timeout to %s', self._timeout)
    else:
      self._logger.debug('set post-startup watchman timeout to %s', self._timeout)
1054278
function Watcher(square, port, silent) {
  var self = this;

  this.square = square;
  this.silent = silent || false;
  this.socket = this.live.call(this, port);
  this.config = path.resolve(process.env.PWD, this.square.package.location);

  // Initialize the live reload, also trigger watching and process the file list.
  this.init = function init() {
    self.watch.apply(self, arguments[1]);
  };

  // Require fs.notify and findit, trigger the watch.
  async.parallel([canihaz['fs.notify'], canihaz.findit], this.init);
}