def _reap_child(self): """ Reap the child process during disconnection. """ if self._reaped: # on_disconnect() may be invoked more than once, for example, if # there is still a pending message to be sent after the first # on_disconnect() call. return try: pid, status = os.waitpid(self.pid, os.WNOHANG) except OSError: e = sys.exc_info()[1] if e.args[0] == errno.ECHILD: LOG.warn('%r: waitpid(%r) produced ECHILD', self.pid, self) return raise self._reaped = True if pid: LOG.debug('%r: child process exit status was %d', self, status) return # For processes like sudo we cannot actually send sudo a signal, # because it is setuid, so this is best-effort only. LOG.debug('%r: child process still alive, sending SIGTERM', self) try: os.kill(self.pid, signal.SIGTERM) except OSError: e = sys.exc_info()[1] if e.args[0] != errno.EPERM: raise
def _on_cache_callback(self, msg, fullname): LOG.debug('%r._on_get_module(): sending %r', self, fullname) tup = self.importer._cache[fullname] if tup is not None: for related in tup[4]: LOG.debug('%r._on_get_module(): trying related %r', self, related) try: rtup = self.importer._cache[related] except KeyError: LOG.warn('%r._on_get_module(): skipping %r, not in cache', self, related) continue self._send_one_module(msg, rtup) self._send_one_module(msg, tup)