当前位置: 首页>>代码示例>>Python>>正文


Python os.wait方法代码示例

本文整理汇总了Python中os.wait方法的典型用法代码示例。如果您正苦于以下问题:Python os.wait方法的具体用法?Python os.wait怎么用?Python os.wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.wait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: workers

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def workers(master_host, master_port, relay_socket_path, num_workers):
    # Start the relay
    master_redis_cfg = {'host': master_host, 'port': master_port}
    relay_redis_cfg = {'unix_socket_path': relay_socket_path}
    if os.fork() == 0:
        RelayClient(master_redis_cfg, relay_redis_cfg).run()
        return
    # Start the workers
    noise = SharedNoiseTable()  # Workers share the same noise
    num_workers = num_workers if num_workers else os.cpu_count()
    logging.info('Spawning {} workers'.format(num_workers))
    for _ in range(num_workers):
        if os.fork() == 0:
            run_worker(relay_redis_cfg, noise=noise)
            return
    os.wait() 
开发者ID:openai,项目名称:evolution-strategies-starter,代码行数:18,代码来源:main.py

示例2: _nanny_thread

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def _nanny_thread(child_proc, pipe, return_val):
    if isinstance(child_proc, int):
        pid, r = os.waitpid(child_proc, 0)
    elif isinstance(child_proc, list):
        while True:
            pid, r = os.wait()
            if pid in child_proc:
                break
    else:
        r = child_proc.wait()
        pid = child_proc.pid

    logging.debug("Nanny thread detected termination "
                  "of pid %s", pid)
    return_val['val'] = r
    return_val['pid'] = pid
    os.write(pipe, 'x') 
开发者ID:cea-hpc,项目名称:pcocc,代码行数:19,代码来源:Misc.py

示例3: test_dummy_thread_after_fork

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def test_dummy_thread_after_fork(self):
        # Issue #14308: a dummy thread in the active list doesn't mess up
        # the after-fork mechanism.
        code = """if 1:
            import thread, threading, os, time

            def background_thread(evt):
                # Creates and registers the _DummyThread instance
                threading.current_thread()
                evt.set()
                time.sleep(10)

            evt = threading.Event()
            thread.start_new_thread(background_thread, (evt,))
            evt.wait()
            assert threading.active_count() == 2, threading.active_count()
            if os.fork() == 0:
                assert threading.active_count() == 1, threading.active_count()
                os._exit(0)
            else:
                os.wait()
        """
        _, out, err = assert_python_ok("-c", code)
        self.assertEqual(out, '')
        self.assertEqual(err, '') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_threading.py

示例4: _run_and_join

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def _run_and_join(self, script):
        script = """if 1:
            import sys, os, time, threading

            # a thread, which waits for the main program to terminate
            def joiningfunc(mainthread):
                mainthread.join()
                print 'end of thread'
        \n""" + script

        p = subprocess.Popen([sys.executable, "-c", script], stdout=subprocess.PIPE)
        rc = p.wait()
        data = p.stdout.read().replace('\r', '')
        p.stdout.close()
        self.assertEqual(data, "end of main\nend of thread\n")
        self.assertFalse(rc == 2, "interpreter was blocked")
        self.assertTrue(rc == 0, "Unexpected error") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_threading.py

示例5: killProcTree

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def killProcTree(pid=None, including_parent=True):
    if not pid:
        # kill the process itself
        pid = os.getpid()
    parent = psutil.Process(pid)
    children = parent.children(recursive=True)
    for child in children:
        child.kill()
    psutil.wait_procs(children, timeout=5)
    if including_parent:
        parent.kill()
        parent.wait(5)


##############################################################################
# Run hashdeep on input file or directory, and output filename to digest mapping
############################################################################## 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:19,代码来源:job_util.py

示例6: workers

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def workers(master_host, master_port, relay_socket_path, num_workers):
    # Start the relay
    master_redis_cfg = {'host': master_host, 'port': master_port}
    relay_redis_cfg = {'unix_socket_path': relay_socket_path}
    if os.fork() == 0:
        RelayClient(master_redis_cfg, relay_redis_cfg).run()
        return
    # Start the workers
    noise = SharedNoiseTable()  # Workers share the same noise
    num_workers = num_workers if num_workers else os.cpu_count()
    print('Spawning workers')
    logging.info('Spawning {} workers'.format(num_workers))
    for _ in range(num_workers):
        if os.fork() == 0:
            run_worker(relay_redis_cfg, noise=noise)
            return
    os.wait() 
开发者ID:AdamStelmaszczyk,项目名称:learning2run,代码行数:19,代码来源:main.py

示例7: launch_user_message_subprocesses

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def launch_user_message_subprocesses(threads: int, output_dir: Path,
                                     consent_message_id: Optional[int]=None) -> None:
    logging.info('Launching %d PARALLEL subprocesses to export UserMessage rows', threads)
    pids = {}

    for shard_id in range(threads):
        arguments = [
            os.path.join(settings.DEPLOY_ROOT, "manage.py"),
            'export_usermessage_batch',
            '--path', str(output_dir),
            '--thread', str(shard_id),
        ]
        if consent_message_id is not None:
            arguments.extend(['--consent-message-id', str(consent_message_id)])

        process = subprocess.Popen(arguments)
        pids[process.pid] = shard_id

    while pids:
        pid, status = os.wait()
        shard = pids.pop(pid)
        print(f'Shard {shard} finished, status {status}') 
开发者ID:zulip,项目名称:zulip,代码行数:24,代码来源:export.py

示例8: http_server

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def http_server():
    """Spawns a HTTP server in a separate process, serving test fixtures.

    Yields base URL of the HTTP server (e.g., http://localhost:1234/)
    """
    oldcwd = os.getcwd()
    os.chdir(pkg_resources.resource_filename('vulnix', 'tests/fixtures'))
    httpd = http.server.HTTPServer(
        ('localhost', 0), http.server.SimpleHTTPRequestHandler)
    port = httpd.server_port
    child = os.fork()
    if child == 0:
        signal.alarm(3600)  # safety belt
        httpd.serve_forever()
        return  # never reached
    os.chdir(oldcwd)
    yield 'http://localhost:{}/'.format(port)
    os.kill(child, signal.SIGTERM)
    os.wait() 
开发者ID:flyingcircusio,项目名称:vulnix,代码行数:21,代码来源:resource_test.py

示例9: test_dummy_thread_after_fork

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def test_dummy_thread_after_fork(self):
        # Issue #14308: a dummy thread in the active list doesn't mess up
        # the after-fork mechanism.
        code = """if 1:
            import _thread, threading, os, time

            def background_thread(evt):
                # Creates and registers the _DummyThread instance
                threading.current_thread()
                evt.set()
                time.sleep(10)

            evt = threading.Event()
            _thread.start_new_thread(background_thread, (evt,))
            evt.wait()
            assert threading.active_count() == 2, threading.active_count()
            if os.fork() == 0:
                assert threading.active_count() == 1, threading.active_count()
                os._exit(0)
            else:
                os.wait()
        """
        _, out, err = assert_python_ok("-c", code)
        self.assertEqual(out, b'')
        self.assertEqual(err, b'') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:test_threading.py

示例10: test_reinit_tls_after_fork

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def test_reinit_tls_after_fork(self):
        # Issue #13817: fork() would deadlock in a multithreaded program with
        # the ad-hoc TLS implementation.

        def do_fork_and_wait():
            # just fork a child process and wait it
            pid = os.fork()
            if pid > 0:
                os.waitpid(pid, 0)
            else:
                os._exit(0)

        # start a bunch of threads that will fork() child processes
        threads = []
        for i in range(16):
            t = threading.Thread(target=do_fork_and_wait)
            threads.append(t)
            t.start()

        for t in threads:
            t.join() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_threading.py

示例11: get_exit_code

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def get_exit_code(self, wait=True):
        """returns the exitcode.
		If wait is False and the worker has not finishef yet, return None."""
        if self.state != self.STATE_INIT:
            if self.worker is None:
                # temp fix for pipes for fast commands
                if not wait:
                    return 0
                while self.worker is None:
                    time.sleep(0.01)
            if wait and self.worker.is_alive():
                self.worker.join()
                self.state = self.STATE_FINISHED
            elif self.worker.status() != self.worker.STOPPED:
                return None
            es = self.worker.state.return_value
            return _get_status(es, self.worker.killer)
        raise RuntimeError("get_exit_code() called before run()!") 
开发者ID:ywangd,项目名称:stash,代码行数:20,代码来源:os_popen.py

示例12: system

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def system(patch, command):
    """Execute the command (a string) in a subshell. This is implemented by calling the Standard C function system(), and has the same limitations. Changes to sys.stdin, etc. are not reflected in the environment of the executed command.

On Unix, the return value is the exit status of the process encoded in the format specified for wait(). Note that POSIX does not specify the meaning of the return value of the C system() function, so the return value of the Python function is system-dependent.

On Windows, the return value is that returned by the system shell after running command, given by the Windows environment variable COMSPEC: on command.com systems (Windows 95, 98 and ME) this is always 0; on cmd.exe systems (Windows NT, 2000 and XP) this is the exit status of the command run; on systems using a non-native shell, consult your shell documentation.

The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes."""
    io = VoidIO()
    worker = _stash.runtime.run(
        input_=command,
        persistent_level=2,
        is_background=False,
        add_to_history=False,
        final_ins=io,
        final_outs=io,
        final_errs=io,
    )
    worker.join()  # wait for completion
    es = worker.state.return_value
    return _get_status(es, worker.killer) 
开发者ID:ywangd,项目名称:stash,代码行数:23,代码来源:os_popen.py

示例13: get_asynchronous_eventlet_pool

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def get_asynchronous_eventlet_pool(size=1000):
    """Return eventlet pool to caller.

    Also store pools created in global list, to wait on
    it after getting signal for graceful shutdown.

    :param size: eventlet pool size
    :returns: eventlet pool
    """
    global ASYNC_EVENTLET_THREAD_POOL_LIST

    pool = eventlet.GreenPool(size=size)
    # Add pool to global ASYNC_EVENTLET_THREAD_POOL_LIST
    ASYNC_EVENTLET_THREAD_POOL_LIST.append(pool)

    return pool 
开发者ID:openstack,项目名称:searchlight,代码行数:18,代码来源:wsgi.py

示例14: wait_on_children

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def wait_on_children(self):
        while self.running:
            try:
                pid, status = os.wait()
                if os.WIFEXITED(status) or os.WIFSIGNALED(status):
                    self._remove_children(pid)
                    self._verify_and_respawn_children(pid, status)
            except OSError as err:
                if err.errno not in (errno.EINTR, errno.ECHILD):
                    raise
            except KeyboardInterrupt:
                LOG.info('Caught keyboard interrupt. Exiting.')
                break
            except exception.SIGHUPInterrupt:
                self.reload()
                continue
        eventlet.greenio.shutdown_safe(self.sock)
        self.sock.close()
        LOG.debug('Exited') 
开发者ID:openstack,项目名称:searchlight,代码行数:21,代码来源:wsgi.py

示例15: test_fork

# 需要导入模块: import os [as 别名]
# 或者: from os import wait [as 别名]
def test_fork(self):
        pgsql = testing.postgresql.Postgresql()
        if os.fork() == 0:
            del pgsql
            pgsql = None
            os.kill(os.getpid(), signal.SIGTERM)  # exit tests FORCELY
        else:
            os.wait()
            sleep(1)
            self.assertTrue(pgsql.is_alive())  # process is alive (delete pgsql obj in child does not effect) 
开发者ID:tk0miya,项目名称:testing.postgresql,代码行数:12,代码来源:test_postgresql.py


注:本文中的os.wait方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。