def activate(self, onTimeout=None, selector=None): """configure the selector and install the timeout callback""" if selector is None: from pathos.selector import Selector selector = Selector() if onTimeout is not None: selector.notifyWhenIdle(onTimeout) self._selector = selector return
def response(self): '''Return the response from the launched process. Return None if no response was received yet from a background process. ''' if self._stdout is None: raise PipeException( "'launch' is required after any reconfiguration") if self._response is not None: return self._response # when running in foreground _pid is 0 (may change to -1) if self._pid <= 0: self._response = self._stdout.read() return self._response # handle response from a background process def onData(selector, fobj): if self.verbose: print("handling pipe response") self._debug.info('on_remote') self._response = fobj.read() selector.state = False return def onTimeout(selector): selector.state = False sel = Selector() #sel._info.activate() sel.notifyOnReadReady(self._stdout, onData) sel.notifyWhenIdle(onTimeout) sel.watch(2.0) # reset _response to None to allow capture of a next response # from a background process return self._response
def response(self): '''Return the response from the launched process. Return None if no response was received yet from a background process. ''' if self._stdout is None: raise PipeException("'launch' is required after any reconfiguration") if self._response is not None: return self._response # when running in foreground _pid is 0 (may change to -1) if self._pid <= 0: self._response = self._stdout.read() return self._response # handle response from a background process def onData(selector, fobj): if self.verbose: print("handling pipe response") self._debug.info('on_remote') self._response = fobj.read() selector.state = False return def onTimeout(selector): selector.state = False sel = Selector() #sel._info.activate() sel.notifyOnReadReady(self._stdout, onData) sel.notifyWhenIdle(onTimeout) sel.watch(2.0) # reset _response to None to allow capture of a next response # from a background process return self._response