Пример #1
0
    def _reap_process_and_children(process, timeout=5):
        "Tries hard to terminate and ultimately kill all the children of this process."
        def on_terminate(proc):
            logger.info("Minecraft process {} terminated with exit code {}".format(proc, proc.returncode))

        procs = process.children(recursive=True) + [process]
        
        # send SIGTERM
        for p in procs:
            try:
                try:
                    import signal
                    os.killpg(os.getpgid(p.pid), signal.SIGTERM)
                except:
                    pass
                p.kill()
            except psutil.NoSuchProcess:
                pass
        gone, alive = psutil.wait_procs(procs, timeout=timeout, callback=on_terminate)
        if alive:
            # send SIGKILL
            for p in alive:
                logger.info("Minecraft process {} survived SIGTERM; trying SIGKILL".format(p.pid))
                try:
                    p.kill()
                except psutil.NoSuchProcess:
                    pass
            gone, alive = psutil.wait_procs(alive, timeout=timeout, callback=on_terminate)
            if alive:
                # give up
                for p in alive:
                    logger.info("Minecraft process {} survived SIGKILL; giving up".format(p.pid))
Пример #2
0
def memory_usage(process):
    try:
        if system() == 'Windows':
            mem = process.memory_full_info().rss
            for child in process.children(recursive=True):
                try:
                    mem += child.memory_full_info().uss
                except:
                    pass
        else:
            mem = process.memory_full_info().pss
            for child in process.children(recursive=True):
                try:
                    mem += child.memory_full_info().uss
                except:
                    pass
        return mem
    except:
        # maybe OS does not allow to query this information ?...
        return 0