def _kill_app(self, method, process_count):

        # range check
        if process_count > 20:
            process_count = 20
        if process_count < 1:
            process_count = 1

        # make a copy of 'sh' shell binary and alter it so it has a unique
        # checksum for this binary, so we don't kill other running instances of
        # bin/sh
        bin_file = self.make_file()
        shutil.copyfile('/bin/sh', bin_file)

        # change the checksum of the binary
        open(bin_file, 'a+b', 0).write('A' * 100)
        os.chmod(bin_file, 0700)  # set exec.. silly macosx

        # launch copied shell binary in background
        processes = {}
        for i in range(process_count):
            proc = subprocess.Popen([bin_file, '-c',
                                     'while true; do sleep 1; done'],
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE,
                                    stdin=subprocess.PIPE)
            processes[proc.pid] = proc

        # call provided method
        method(bin_file)

        i = 0
        while i < 1500:
            i += 1

            try:
                # wait for the processes to die; reclaim process entries
                pid, status = os.waitpid(-1, os.P_NOWAIT)
                time.sleep(0.05)
            except OSError:
                break

            if pid in processes:
                del processes[pid]

        fail = False
        if processes:
            fail = True

            # kill what's leftover
            for pid, proc in processes.iteritems():
                try:
                    proc.terminate()
                    proc.wait()
                except OSError:
                    pass

        return (not fail)
Counts all matched objects.
dataset/ETHPy150Open xtrementl/focus/tests/unit/plugin/modules/test_apps.py/CloseAppCase._kill_app--crossover with--dataset/ETHPy150Open lektor/lektor/lektor/db.py/Query.count