Exemple #1
0
    def shutdown(self, timeout=1.0):
        """Shutdown the subprocess.

        This method tries to shutdown the subprocess cleanly, waits until
        timeout expires, then terminates it.
        """
        if not self.is_running:
            return

        # we're about to shut down, tell our responder
        trapcall.trap_call("subprocess shutdown", self.responder.on_shutdown)
        # Politely ask our process to shutdown
        self.send_quit()
        # If things go right, the process will quit, then our thread will
        # quit.  Wait for a clean shutdown
        self.thread.join(timeout)
        # If things didn't shutdown, then force them to quit.  Let's not
        # bother with SIGTERM since that really also would be an abnormal
        # exit as far as the child is concerned.
        try:
            self.process.kill()
        except OSError, e:
            # Error on kill.  Just log an error and move on.  Nothing
            # much we can do here anyway.
            logging.exception('worker subprocess kill failed')
Exemple #2
0
    def shutdown(self, timeout=1.0):
        """Shutdown the subprocess.

        This method tries to shutdown the subprocess cleanly, waits until
        timeout expires, then terminates it.
        """
        if not self.is_running:
            return

        # we're about to shut down, tell our responder
        trapcall.trap_call("subprocess shutdown", self.responder.on_shutdown)
        # Politely ask our process to shutdown
        self.send_quit()
        # If things go right, the process will quit, then our thread will
        # quit.  Wait for a clean shutdown
        self.thread.join(timeout)
        # If things didn't shutdown, then force them to quit
        if self.process.returncode is None:
            try:
                self.process.terminate()
            except OSError, e:
                # Error on terminate.  Normally we should log an error, except
                # in the case where the process quit by itself before our
                # terminate() call (see #18172).
                if self.process.returncode is None:
                    logging.exception("error calling terminate()")
Exemple #3
0
    def shutdown(self, timeout=1.0):
        """Shutdown the subprocess.

        This method tries to shutdown the subprocess cleanly, waits until
        timeout expires, then terminates it.
        """
        if not self.is_running:
            return

        # we're about to shut down, tell our responder
        trapcall.trap_call("subprocess shutdown", self.responder.on_shutdown)
        # Politely ask our process to shutdown
        self.send_quit()
        # If things go right, the process will quit, then our thread will
        # quit.  Wait for a clean shutdown
        self.thread.join(timeout)
        # If things didn't shutdown, then force them to quit.  Let's not
        # bother with SIGTERM since that really also would be an abnormal
        # exit as far as the child is concerned.
        try:
            self.process.kill()
        except OSError, e:
            # Error on kill.  Just log an error and move on.  Nothing
            # much we can do here anyway.
            logging.exception('worker subprocess kill failed')
Exemple #4
0
 def _restart(self):
     # close our stream to the subprocess
     self.process.stdin.close()
     # unset our attributes for the process that just quit.  This protects
     # us in case _start() fails for some reason.
     self._cleanup_process()
     # restart ourselves
     self._start()
     trapcall.trap_call("subprocess restart", self.responder.on_restart)
Exemple #5
0
 def _restart(self):
     # close our stream to the subprocess
     self.process.stdin.close()
     # unset our attributes for the process that just quit.  This protects
     # us in case _start() fails for some reason.
     self._cleanup_process()
     # restart ourselves
     self._start()
     trapcall.trap_call("subprocess restart", self.responder.on_restart)
Exemple #6
0
 def _start(self):
     """Does the work to startup a new process/thread."""
     # create our child process.
     self.process = self._start_subprocess()
     # create thread to handle the subprocess's output.  It would be nice
     # to eliminate this thread, but I don't see an easy way to integrate
     # it into the eventloop, since windows doesn't have support for
     # select() on pipes.
     #
     # This thread only handles the subprocess output.  We write to the
     # subprocess stdin from the eventloop.
     self.thread = SubprocessResponderThread(self.process.stdout,
             self.responder, self._on_thread_quit)
     self.thread.daemon = True
     self.thread.start()
     # work is all done, do some finishing touches
     self.is_running = True
     self._send_startup_info()
     trapcall.trap_call("subprocess startup", self.responder.on_startup)
Exemple #7
0
 def _start(self):
     """Does the work to startup a new process/thread."""
     # create our child process.
     self.process = self._start_subprocess()
     # create thread to handle the subprocess's output.  It would be nice
     # to eliminate this thread, but I don't see an easy way to integrate
     # it into the eventloop, since windows doesn't have support for
     # select() on pipes.
     #
     # This thread only handles the subprocess output.  We write to the
     # subprocess stdin from the eventloop.
     self.thread = SubprocessResponderThread(self.process.stdout,
             self.responder, self._on_thread_quit)
     self.thread.daemon = True
     self.thread.start()
     # work is all done, do some finishing touches
     self.is_running = True
     self._send_startup_info()
     trapcall.trap_call("subprocess startup", self.responder.on_startup)
Exemple #8
0
    def shutdown(self, timeout=1.0):
        """Shutdown the subprocess.

        This method tries to shutdown the subprocess cleanly, waits until
        timeout expires, then terminates it.
        """
        if not self.is_running:
            return

        # we're about to shut down, tell our responder
        trapcall.trap_call("subprocess shutdown", self.responder.on_shutdown)
        # Politely ask our process to shutdown
        self.send_quit()
        # If things go right, the process will quit, then our thread will
        # quit.  Wait for a clean shutdown
        self.thread.join(timeout)
        # If things didn't shutdown, then force them to quit
        if self.process.returncode is None:
            self.process.terminate()
        self._cleanup_process()
Exemple #9
0
    def shutdown(self, timeout=1.0):
        """Shutdown the subprocess.

        This method tries to shutdown the subprocess cleanly, waits until
        timeout expires, then terminates it.
        """
        if not self.is_running:
            return

        # we're about to shut down, tell our responder
        trapcall.trap_call("subprocess shutdown", self.responder.on_shutdown)
        # Politely ask our process to shutdown
        self.send_quit()
        # If things go right, the process will quit, then our thread will
        # quit.  Wait for a clean shutdown
        self.thread.join(timeout)
        # If things didn't shutdown, then force them to quit
        if self.process.returncode is None:
            self.process.terminate()
        self._cleanup_process()
Exemple #10
0
 def dispatch(self):
     success = True
     if not self.canceled:
         when = "While handling %s" % self.name
         start = clock()
         success = trapcall.trap_call(when, self.function, *self.args,
                 **self.kwargs)
         end = clock()
         if end-start > 0.5:
             logging.timing("%s too slow (%.3f secs)",
                            self.name, end-start)
         try:
             total = cumulative[self.name]
         except (KeyError, AttributeError):
             total = 0
         total += end - start
         cumulative[self.name] = total
         if total > 5.0:
             logging.timing("%s cumulative is too slow (%.3f secs)",
                            self.name, total)
             cumulative[self.name] = 0
     self._unlink()
     return success
Exemple #11
0
 def invoke_errback(self, error):
     trapcall.trap_call('query_echonest errback', self.errback,
                        self.path, error)
Exemple #12
0
 def invoke_callback(self):
     trapcall.trap_call('query_echonest callback', self.callback,
                        self.path, self.metadata)
Exemple #13
0
 def callback_event():
     success = trapcall.trap_call(when, function)
     if not success:
         del map_[fd]
     return success
Exemple #14
0
def timeout_wrapper(func, *args, **kwargs):
    trapcall.trap_call('GTK Timeout', func, *args, **kwargs)
    return False
Exemple #15
0
 def run_(self, info):
     trapcall.trap_call('Timeout', self.func, *self.args, **self.kwargs)
Exemple #16
0
 def invoke_callback(self):
     trapcall.trap_call('query_echonest callback', self.callback, self.path,
                        self.metadata)
Exemple #17
0
 def invoke_errback(self, error):
     trapcall.trap_call('query_echonest errback', self.errback, self.path,
                        error)
Exemple #18
0
def timeout_wrapper(func, *args, **kwargs):
    trapcall.trap_call('GTK Timeout', func, *args, **kwargs)
    return False
Exemple #19
0
 def run_(self, info):
     trapcall.trap_call('Timeout', self.func, *self.args, **self.kwargs)