當前位置: 首頁>>代碼示例>>Python>>正文


Python os.wait4方法代碼示例

本文整理匯總了Python中os.wait4方法的典型用法代碼示例。如果您正苦於以下問題:Python os.wait4方法的具體用法?Python os.wait4怎麽用?Python os.wait4使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.wait4方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: wait_for_child_and_forward_signals

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def wait_for_child_and_forward_signals(child_pid, process_name):
    """Wait for a child to terminate and in the meantime forward all signals
    that the current process receives to this child.
    @return a tuple of exit code and resource usage of the child as given by os.waitpid
    """
    block_all_signals()

    while True:
        logging.debug("Waiting for signals")
        signum = signal.sigwait(_ALL_SIGNALS)
        if signum == signal.SIGCHLD:
            pid, exitcode, ru_child = os.wait4(-1, os.WNOHANG)
            while pid != 0:
                if pid == child_pid:
                    return exitcode, ru_child
                else:
                    logging.debug("Received unexpected SIGCHLD for PID %s", pid)
                pid, exitcode, ru_child = os.wait4(-1, os.WNOHANG)

        else:
            _forward_signal(signum, child_pid, process_name) 
開發者ID:sosy-lab,項目名稱:benchexec,代碼行數:23,代碼來源:container.py

示例2: wait_impl

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def wait_impl(self, cpid):
        option = os.WNOHANG
        if sys.platform.startswith('aix'):
            # Issue #11185: wait4 is broken on AIX and will always return 0
            # with WNOHANG.
            option = 0
        for i in range(10):
            # wait4() shouldn't hang, but some of the buildbots seem to hang
            # in the forking tests.  This is an attempt to fix the problem.
            spid, status, rusage = os.wait4(cpid, option)
            if spid == cpid:
                break
            time.sleep(1.0)
        self.assertEqual(spid, cpid)
        self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
        self.assertTrue(rusage) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_wait4.py

示例3: wait_impl

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def wait_impl(self, cpid):
        option = os.WNOHANG
        if sys.platform.startswith('aix'):
            # Issue #11185: wait4 is broken on AIX and will always return 0
            # with WNOHANG.
            option = 0
        deadline = time.monotonic() + 10.0
        while time.monotonic() <= deadline:
            # wait4() shouldn't hang, but some of the buildbots seem to hang
            # in the forking tests.  This is an attempt to fix the problem.
            spid, status, rusage = os.wait4(cpid, option)
            if spid == cpid:
                break
            time.sleep(0.1)
        self.assertEqual(spid, cpid)
        self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
        self.assertTrue(rusage) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,代碼來源:test_wait4.py

示例4: exec_child

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def exec_child(self, executable, environ=None, stdin=None, stdout=None, stderr=None, cwd=None):
        '''Execute a child process with the environment set from the current environment, the
        values of self.addtl_child_environ, the random numbers returned by self.random_val_env_vars, and
        the given ``environ`` (applied in that order). stdin/stdout/stderr are optionally redirected.
        
        This function waits on the child process to finish, then returns
        (rc, rusage), where rc is the child's return code and rusage is the resource usage tuple from os.wait4()'''
        
        all_environ = dict(os.environ)
        all_environ.update(self.addtl_child_environ)
        all_environ.update(self.random_val_env_vars())
        all_environ.update(environ or {})
        
        stdin  = open(stdin, 'rb') if stdin else sys.stdin        
        stdout = open(stdout, 'wb') if stdout else sys.stdout
        if stderr == 'stdout':
            stderr = stdout
        else:
            stderr = open(stderr, 'wb') if stderr else sys.stderr
                
        # close_fds is critical for preventing out-of-file errors
        proc = subprocess.Popen([executable],
                                cwd = cwd,
                                stdin=stdin, stdout=stdout, stderr=stderr if stderr != stdout else subprocess.STDOUT,
                                close_fds=True, env=all_environ)

        # Wait on child and get resource usage
        (_pid, _status, rusage) = os.wait4(proc.pid, 0)
        # Do a subprocess.Popen.wait() to let the Popen instance (and subprocess module) know that
        # we are done with the process, and to get a more friendly return code
        rc = proc.wait()
        return (rc, rusage) 
開發者ID:westpa,項目名稱:westpa,代碼行數:34,代碼來源:executable.py

示例5: _wait_for_process

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def _wait_for_process(self, pid, name):
        """Wait for the given process to terminate.
        @return tuple of exit code and resource usage
        """
        try:
            logging.debug("Waiting for process %s with pid %s", name, pid)
            unused_pid, exitcode, ru_child = os.wait4(pid, 0)
            return exitcode, ru_child
        except OSError as e:
            if self.PROCESS_KILLED and e.errno == errno.EINTR:
                # Interrupted system call seems always to happen
                # if we killed the process ourselves after Ctrl+C was pressed
                # We can try again to get exitcode and resource usage.
                logging.debug(
                    "OSError %s while waiting for termination of %s (%s): %s.",
                    e.errno,
                    name,
                    pid,
                    e.strerror,
                )
                try:
                    unused_pid, exitcode, ru_child = os.wait4(pid, 0)
                    return exitcode, ru_child
                except OSError:
                    pass  # original error will be handled and this ignored

            logging.critical(
                "OSError %s while waiting for termination of %s (%s): %s.",
                e.errno,
                name,
                pid,
                e.strerror,
            )
            return 0, None 
開發者ID:sosy-lab,項目名稱:benchexec,代碼行數:36,代碼來源:baseexecutor.py

示例6: wait_impl

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def wait_impl(self, cpid):
        for i in range(10):
            # wait4() shouldn't hang, but some of the buildbots seem to hang
            # in the forking tests.  This is an attempt to fix the problem.
            spid, status, rusage = os.wait4(cpid, os.WNOHANG)
            if spid == cpid:
                break
            time.sleep(1.0)
        self.assertEqual(spid, cpid)
        self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
        self.assertTrue(rusage) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:13,代碼來源:test_wait4.py

示例7: test_wait4

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def test_wait4(self):
        self._test_wait_single(lambda pid: os.wait4(pid, 0)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:4,代碼來源:eintr_tester.py

示例8: close

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def close(self):
        # Errors from closing pipes or wait4() are unlikely, but possible.

        # Ideally would give up waiting after a while and forcibly terminate the
        # subprocess.
        errors = []
        try:
            self.command_pipe.close()
        except EnvironmentError, e:
            errors.append("error closing command pipe:\n%s" % e) 
開發者ID:pnprog,項目名稱:goreviewpartner,代碼行數:12,代碼來源:gtp_controller.py

示例9: record_child_pid

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def record_child_pid(
    pid: int, record_paths: "RecordPaths", timeout: Optional[int] = None
) -> Recording:

    if timeout is None:
        options = 0
    else:
        options = os.WNOHANG

    record = RecordProcess(pid, record_paths)

    with record:
        ptrace_detach(pid)
        start = time.time()

        while True:
            pid, exit_code, rusage = os.wait4(pid, options)
            if pid != 0:
                break
            elif timeout is not None and time.time() - start <= 0:
                raise TimeoutExpired(
                    "process did not finish within {} seconds".format(timeout)
                )
            time.sleep(0.10)
        coredump, trace = record.result()
        return Recording(coredump, trace, exit_code, rusage) 
開發者ID:hase-project,項目名稱:hase,代碼行數:28,代碼來源:__init__.py

示例10: main

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def main() -> None:

    result_file = Path(args.outdir).joinpath("result.json").resolve()
    results: Dict[str, Any] = {args.name: {"original": [], "hase": []}}

    for i in range(args.n):
        results[args.name]["hase"].append(dict(run=i, result=[], valid=True))
        with TemporaryDirectory() as tempdir:
            temppath = Path(tempdir)
            recording = record(
                target=args.args,
                record_path=temppath,
                log_path=temppath.joinpath("logs"),
                stdout=open(f"{args.outdir}/{args.name}_hase_{i}.out", "w"),
                limit=1,
            )
            if recording:
                rusage = recording.rusage
                if rusage:
                    results[args.name]["hase"][i]["result"].append(list(rusage))

        results[args.name]["original"].append(dict(run=i, result=[], valid=True))

        process = subprocess.Popen(
            args.args, stdout=open(f"{args.outdir}/{args.name}_{i}.out", "w")
        )
        _, _, rusage = os.wait4(process.pid, 0)
        if rusage:
            results[args.name]["original"][i]["result"].append(list(rusage))

    with open(result_file, "w") as file:
        json.dump(results, file, sort_keys=True, indent=4, separators=(",", ": "))
        file.write("\n")

    return 
開發者ID:hase-project,項目名稱:hase,代碼行數:37,代碼來源:benchmark.py

示例11: main

# 需要導入模塊: import os [as 別名]
# 或者: from os import wait4 [as 別名]
def main():
    args = get_options()

    if args.show_id:
        show_current_users_and_groups()
        sys.exit(0)

    mamaji_data = fetch_mamaji_data(args)
    filter_options(mamaji_data)

    target_cmd = None
    if args.cmd:
        target_cmd = args.cmd

    if not args.do_fork:
        change_users_and_groups(mamaji_data)
        # if target_cmd is None, do nothing
        if target_cmd:
            os.execlp(target_cmd[0], *target_cmd)
        sys.exit(0)

    if args.do_fork and not args.cmd:
        target_cmd = [find_shell()]

    pid = os.fork()
    if pid == -1:
        warn('failed to do fork')
        sys.exit(1)
    elif pid == 0:
        change_users_and_groups(mamaji_data)
        os.execlp(target_cmd[0], *target_cmd)
    else:
        status = os.wait4(pid, 0)[1] >> 8
        sys.exit(status) 
開發者ID:procszoo,項目名稱:procszoo,代碼行數:36,代碼來源:mamaji.py


注:本文中的os.wait4方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。