Best Python code snippet using avocado_python
process.py
Source:process.py  
...194                    positive=number_of_seconds)195    :return: list of all PIDs we sent signal to196    :rtype: list197    """198    def _all_pids_dead(killed_pids):199        for pid in killed_pids:200            if pid_exists(pid):201                return False202        return True203    if sig is None:204        sig = signal.SIGKILL205    if timeout > 0:206        start = time.monotonic()207    if not safe_kill(pid, signal.SIGSTOP):208        return [pid]209    killed_pids = [pid]210    for child in get_children_pids(pid):211        killed_pids.extend(kill_process_tree(int(child), sig, False))212    safe_kill(pid, sig)213    if send_sigcont:214        for pid in killed_pids:215            safe_kill(pid, signal.SIGCONT)216    if timeout == 0:217        return killed_pids218    elif timeout > 0:219        if not wait_for(_all_pids_dead, timeout + start - time.monotonic(),220                        step=0.01, args=(killed_pids[::-1],)):221            raise RuntimeError("Timeout reached when waiting for pid %s "222                               "and children to die (%s)" % (pid, timeout))223    else:224        while not _all_pids_dead(killed_pids[::-1]):225            time.sleep(0.01)226    return killed_pids227def kill_process_by_pattern(pattern):228    """229    Send SIGTERM signal to a process with matched pattern.230    :param pattern: normally only matched against the process name231    """232    cmd = "pkill -f %s" % pattern233    result = run(cmd, ignore_status=True)234    if result.exit_status:235        LOG.error("Failed to run '%s': %s", cmd, result)236    else:237        LOG.info("Succeed to run '%s'.", cmd)238def process_in_ptree_is_defunct(ppid):...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
