예제 #1
0
 def echo(self, n):
     context = Context.current()
     for x in range(n):
         context.progress.details = 'hello {}'.format(x)
         context.progress.report()
         sleep(0.25)
     return n
예제 #2
0
파일: parent.py 프로젝트: darinlively/gofer
 def __call__(self):
     """
     Relay to RMI context progress reporter.
     """
     context = Context.current()
     context.progress.__dict__.update(self.payload.__dict__)
     context.progress.report()
예제 #3
0
파일: child.py 프로젝트: jortel/gofer
 def __call__(self, pipe):
     """
     Perform RMI on the child-side of the forked call
     as follows:
       - Reset the RMI context.
       - Invoke the method
       - Send result: retval, progress, raised exception.
     All output is sent to the parent using the inter-process pipe.
     :param pipe: A message pipe.
     :type  pipe: gofer.mp.Pipe
     """
     pipe.writer = Writer(pipe.writer.fd)
     try:
         pipe.reader.close()
         monitor = ParentMonitor(pipe.writer)
         monitor.start()
         context = Context.current()
         context.cancelled = self._not_cancelled()
         context.progress = Progress(pipe.writer)
         result = self.method(*self.args, **self.kwargs)
         reply = protocol.Result(result)
         reply.send(pipe.writer)
     except PipeBroken:
         log.debug('Pipe broken.')
     except Exception as e:
         log.exception(str(e))
         reply = protocol.Raised(e)
         reply.send(pipe.writer)
예제 #4
0
파일: child.py 프로젝트: swipswaps/gofer
 def __call__(self, pipe):
     """
     Perform RMI on the child-side of the forked call
     as follows:
       - Reset the RMI context.
       - Invoke the method
       - Send result: retval, progress, raised exception.
     All output is sent to the parent using the inter-process pipe.
     :param pipe: A message pipe.
     :type  pipe: gofer.mp.Pipe
     """
     pipe.writer = Writer(pipe.writer.fd)
     try:
         pipe.reader.close()
         monitor = ParentMonitor(pipe.writer)
         monitor.start()
         context = Context.current()
         context.cancelled = self._not_cancelled()
         context.progress = Progress(pipe.writer)
         result = self.method(*self.args, **self.kwargs)
         reply = protocol.Result(result)
         reply.send(pipe.writer)
     except PipeBroken:
         log.debug('Pipe broken.')
     except Exception as e:
         log.exception(str(e))
         reply = protocol.Raised(e)
         reply.send(pipe.writer)
예제 #5
0
파일: parent.py 프로젝트: swipswaps/gofer
 def __call__(self):
     """
     Relay to RMI context progress reporter.
     """
     context = Context.current()
     context.progress.__dict__.update(self.payload.__dict__)
     context.progress.report()
예제 #6
0
파일: shell.py 프로젝트: jortel/gofer
 def report(self, details):
     """
     Report progress.
     :param details: The details to report.
     :type details: dict
     """
     if not self.progress_reported:
         # not enabled
         return
     context = Context.current()
     context.progress.details = details
     context.progress.report()
예제 #7
0
 def report(self, details):
     """
     Report progress.
     :param details: The details to report.
     :type details: dict
     """
     if not self.progress_reported:
         # not enabled
         return
     context = Context.current()
     context.progress.details = details
     context.progress.report()
예제 #8
0
파일: shell.py 프로젝트: jortel/gofer
 def run(self, *command):
     """
     Run the specified command.
     :param command: A command and parameters.
     :type command: Iterable
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     """
     details = {
         STDOUT: '',
         STDERR: '',
     }
     result = {
         STDOUT: '',
         STDERR: '',
     }
     context = Context.current()
     p = Popen(command, stdout=PIPE, stderr=PIPE)
     try:
         while True:
             n_read = 0
             if context.cancelled():
                 p.terminate()
                 break
             for fp, key in ((p.stdout, STDOUT), (p.stderr, STDERR)):
                 line = fp.readline()
                 if line:
                     n_read += len(line)
                     details[key] = line
                     result[key] += line
                     self.report(details)
             if not n_read:
                 #  EOF
                 break
         p.stdout.close()
         p.stderr.close()
         status = p.wait()
         return status, result
     except OSError as e:
         return -1, str(e)
예제 #9
0
 def run(self, *command):
     """
     Run the specified command.
     :param command: A command and parameters.
     :type command: Iterable
     :return: (status, {stdout:<str>, stderr:<str>})
     :rtype: tuple
     """
     details = {
         STDOUT: '',
         STDERR: '',
     }
     result = {
         STDOUT: '',
         STDERR: '',
     }
     context = Context.current()
     p = Popen(command, stdout=PIPE, stderr=PIPE)
     try:
         while True:
             n_read = 0
             if context.cancelled():
                 p.terminate()
                 break
             for fp, key in ((p.stdout, STDOUT), (p.stderr, STDERR)):
                 line = fp.readline()
                 if line:
                     n_read += len(line)
                     details[key] = line
                     result[key] += line
                     self.report(details)
             if not n_read:
                 #  EOF
                 break
         p.stdout.close()
         p.stderr.close()
         status = p.wait()
         return status, result
     except OSError as e:
         return -1, str(e)
예제 #10
0
파일: child.py 프로젝트: darinlively/gofer
 def __call__(self, pipe):
     """
     Perform RMI on the child-side of the forked call
     as follows:
       - Reset the RMI context.
       - Invoke the method
       - Send result: retval, progress, raised exception.
     All output is sent to the parent using the inter-process pipe.
     :param pipe: A message pipe.
     :type  pipe: multiprocessing.Connection
     """
     try:
         context = Context.current()
         context.cancelled = lambda: False
         context.progress = Progress(pipe)
         result = self.method(*self.args, **self.kwargs)
         reply = protocol.Result(result)
         reply.send(pipe)
     except Exception, e:
         log.exception(utf8(e))
         reply = protocol.Raised(e)
         reply.send(pipe)
예제 #11
0
파일: parent.py 프로젝트: darinlively/gofer
 def __call__(self):
     """
     Invoke the RMI as follows:
       - Fork
       - Start the monitor.
       - Read and dispatch reply messages.
     :return: Whatever method returned.
     """
     inbound, outbound = Pipe()
     target = Target(self.method, *self.args, **self.kwargs)
     child = Process(target=target, args=(outbound,))
     monitor = Monitor(Context.current(), child, outbound)
     try:
         child.start()
         monitor.start()
         retval = self.read(inbound)
         return retval
     finally:
         inbound.close()
         outbound.close()
         monitor.stop()
         child.join()
예제 #12
0
파일: parent.py 프로젝트: swipswaps/gofer
 def __call__(self):
     """
     Invoke the RMI as follows:
       - Fork
       - Start the monitor.
       - Read and dispatch reply messages.
     :return: Whatever method returned.
     """
     pipe = Pipe()
     target = Target(self.method, *self.args, **self.kwargs)
     child = Process(target, pipe)
     monitor = Monitor(Context.current(), child)
     try:
         child.start()
         monitor.start()
         pipe.writer.close()
         retval = self.read(pipe.reader)
         return retval
     finally:
         pipe.close()
         monitor.stop()
         child.wait()
예제 #13
0
 def __call__(self, pipe):
     """
     Perform RMI on the child-side of the forked call
     as follows:
       - Reset the RMI context.
       - Invoke the method
       - Send result: retval, progress, raised exception.
     All output is sent to the parent using the inter-process pipe.
     :param pipe: A message pipe.
     :type  pipe: gofer.mp.Writer
     """
     try:
         context = Context.current()
         context.cancelled = lambda: False
         context.progress = Progress(pipe)
         result = self.method(*self.args, **self.kwargs)
         reply = protocol.Result(result)
         reply.send(pipe)
     except Exception, e:
         log.exception(utf8(e))
         reply = protocol.Raised(e)
         reply.send(pipe)