def _on_check(self, handle):
        # this function check if a process that need to be stopped after
        # a given graceful time is still in the stopped process. If yes
        # the process is killed. It let the possibility to let the time
        # to some worker to quit.
        #
        # The garbage collector run eveyry 0.1s .
        with self._lock:
            while True:
                if not len(self.processes):
                    # done callback has been set, run it
                    if self._done_cb is not None:
                        self._done_cb()
                        self._donc_cb = None

                    # nothing in the queue, quit
                    break

                # check the diff between the time it is now and the
                # graceful time set when the worker was stopped
                p = heapq.heappop(self.processes)
                now = nanotime()
                delta = p.graceful_time - now
                if delta > 0:
                    # we have anything to do, put the process back in
                    # the heap and return
                    if p.active:
                        heapq.heappush(self.processes, p)
                    break
                else:
                    # a process need to be kill. Send a SIGKILL signal
                    try:
                        p.kill(signal.SIGKILL)
                    except:
                        pass

                    # and close it. (maybe we should just close it)
                    p.close()
dataset/ETHPy150Open benoitc/gaffer/gaffer/state.py/ProcessTracker._on_check/original