예제 #1
0
 def _handleMessageFromChild(self, selector, fd):
     """handler for message from a child process"""
     
     line = _str(fd.readline())
     if line[:4] == 'done':
         pid = self._activeProcesses[fd]
         os.waitpid(pid, 0)
     self._unRegisterChild(fd)
예제 #2
0
    def _handleMessageFromChild(self, selector, fd):
        """handler for message from a child process"""

        line = _str(fd.readline())
        if line[:4] == 'done':
            pid = self._activeProcesses[fd]
            os.waitpid(pid, 0)
        self._unRegisterChild(fd)
예제 #3
0
 def onChild(pid, fromparent, toparent):
     try:
         response = self._server._marshaled_dispatch(data)
         self._sendResponse(response)
         line = _str(fromparent.readline())
         toparent.write(_b('done\n'))
         toparent.flush()
     except:
         logger(name='pathos.xmlrpc', level=30).error(print_exc_info())
     os._exit(0)
예제 #4
0
 def onChild(pid, fromparent, toparent):
     try:
         response = self._server._marshaled_dispatch(data)
         self._sendResponse(response)
         line = _str(fromparent.readline())
         toparent.write(_b('done\n'))
         toparent.flush()
     except:
         logger(name='pathos.xmlrpc', level=30).error(print_exc_info())
     os._exit(0)
예제 #5
0
    def response(self):
        '''Return the response from the launched process.
        Return None if no response was received yet from a background process.
        ''' #XXX: if PY3, return bytes, decode to ascii, take encoding, or ???

        if self._stdout is None:
            raise PipeException(
                "'launch' is required after any reconfiguration")
        if self.codec is True: codec = 'ascii'
        elif self.codec is False: codec = False
        elif self.codec is None: codec = False
        else: codec = self.codec
        if self._response is not None: return _str(self._response, codec)

        # when running in foreground _pid is 0 (may change to -1)
        if self._pid <= 0:
            self._response = self._stdout.read()
            return _str(self._response, codec)

        # 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 _str(self._response, codec)
예제 #6
0
    def response(self):
        '''Return the response from the launched process.
        Return None if no response was received yet from a background process.
        ''' #XXX: if PY3, return bytes, decode to ascii, take encoding, or ??? 

        if self._stdout is None:
            raise PipeException("'launch' is required after any reconfiguration")
        if self.codec is True: codec = 'ascii'
        elif self.codec is False: codec = False
        elif self.codec is None: codec = False
        else: codec = self.codec
        if self._response is not None: return _str(self._response, codec)

        # when running in foreground _pid is 0 (may change to -1)
        if self._pid <= 0:
            self._response = self._stdout.read()
            return _str(self._response, codec)
        
        # 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 _str(self._response, codec)
예제 #7
0
파일: spawn.py 프로젝트: vreuter/pathos
 def onChild(pid, fromparent, toparent):
     toparent.write(_b('hello dad\n'))
     toparent.flush()
     s = _str(fromparent.readline())
     print(s, end='')
     os._exit(0)
예제 #8
0
파일: spawn.py 프로젝트: vreuter/pathos
 def onParent(pid, fromchild, tochild):
     s = _str(fromchild.readline())
     print(s, end='')
     tochild.write(_b('hello son\n'))
     tochild.flush()
     os.wait()
예제 #9
0
 def onChild(pid, fromparent, toparent):
     toparent.write(_b('hello dad\n'))
     toparent.flush()
     s = _str(fromparent.readline())
     print(s, end='')
     os._exit(0)
예제 #10
0
 def onParent(pid, fromchild, tochild):
     s = _str(fromchild.readline())
     print(s, end='')
     tochild.write(_b('hello son\n'))
     tochild.flush()
     os.wait()