Best Python code snippet using autotest_python
parallel.py
Source:parallel.py  
...45            sys.stdout.flush()46            sys.stderr.flush()47        finally:48            os._exit(0)49def _check_for_subprocess_exception(temp_dir, pid):50    ename = temp_dir + "/debug/error-%d" % pid51    if os.path.exists(ename):52        try:53            e = pickle.load(file(ename, 'r'))54        except ImportError:55            with open(ename, 'r') as fp:56                file_text = fp.read()57            raise error.TestError(58                    'Subprocess raised an exception that could not be '59                    'identified. The root cause exception is in the text '60                    'that follows: ' + file_text)61        finally:62            # Rename the error-pid file so that they do not affect later child63            # processes that use recycled pids.64            i = 065            while True:66                pename = ename + ('-%d' % i)67                i += 168                if not os.path.exists(pename):69                    break70            os.rename(ename, pename)71        raise e72def fork_waitfor(tmp, pid):73    (pid, status) = os.waitpid(pid, 0)74    _check_for_subprocess_exception(tmp, pid)75    if status:76        raise error.TestError("Test subprocess failed rc=%d" % (status))77def fork_waitfor_timed(tmp, pid, timeout):78    """79    Waits for pid until it terminates or timeout expires.80    If timeout expires, test subprocess is killed.81    """82    timer_expired = True83    poll_time = 284    time_passed = 085    while time_passed < timeout:86        time.sleep(poll_time)87        (child_pid, status) = os.waitpid(pid, os.WNOHANG)88        if (child_pid, status) == (0, 0):89            time_passed = time_passed + poll_time90        else:91            timer_expired = False92            break93    if timer_expired:94        logging.info('Timer expired (%d sec.), nuking pid %d', timeout, pid)95        utils.nuke_pid(pid)96        (child_pid, status) = os.waitpid(pid, 0)97        raise error.TestError("Test timeout expired, rc=%d" % (status))98    else:99        _check_for_subprocess_exception(tmp, pid)100    if status:101        raise error.TestError("Test subprocess failed rc=%d" % (status))102def fork_nuke_subprocess(tmp, pid):103    utils.nuke_pid(pid)...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!!
