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


Python multiprocessing.active_children方法代码示例

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


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

示例1: test_multiprocessing

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_multiprocessing(app):
    """Tests that the number of children we produce is correct"""
    # Selects a number at random so we can spot check
    num_workers = random.choice(range(2, multiprocessing.cpu_count() * 2 + 1))
    process_list = set()

    def stop_on_alarm(*args):
        for process in multiprocessing.active_children():
            process_list.add(process.pid)
            process.terminate()

    signal.signal(signal.SIGALRM, stop_on_alarm)
    signal.alarm(3)
    app.run(HOST, PORT, workers=num_workers)

    assert len(process_list) == num_workers 
开发者ID:huge-success,项目名称:sanic,代码行数:18,代码来源:test_multiprocessing.py

示例2: test_multiprocessing_with_blueprint

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_multiprocessing_with_blueprint(app):
    # Selects a number at random so we can spot check
    num_workers = random.choice(range(2, multiprocessing.cpu_count() * 2 + 1))
    process_list = set()

    def stop_on_alarm(*args):
        for process in multiprocessing.active_children():
            process_list.add(process.pid)
            process.terminate()

    signal.signal(signal.SIGALRM, stop_on_alarm)
    signal.alarm(3)

    bp = Blueprint("test_text")
    app.blueprint(bp)
    app.run(HOST, PORT, workers=num_workers)

    assert len(process_list) == num_workers


# this function must be outside a test function so that it can be
# able to be pickled (local functions cannot be pickled). 
开发者ID:huge-success,项目名称:sanic,代码行数:24,代码来源:test_multiprocessing.py

示例3: test_terminate

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_terminate(self):
        if self.TYPE == 'threads':
            self.skipTest('test not appropriate for {}'.format(self.TYPE))

        p = self.Process(target=self._test_terminate)
        p.daemon = True
        p.start()

        self.assertEqual(p.is_alive(), True)
        self.assertIn(p, self.active_children())
        self.assertEqual(p.exitcode, None)

        p.terminate()

        join = TimingWrapper(p.join)
        self.assertEqual(join(), None)
        self.assertTimingAlmostEqual(join.elapsed, 0.0)

        self.assertEqual(p.is_alive(), False)
        self.assertNotIn(p, self.active_children())

        p.join()

        # XXX sometimes get p.exitcode == 0 on Windows ...
        #self.assertEqual(p.exitcode, -signal.SIGTERM) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_multiprocessing.py

示例4: tearDownClass

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def tearDownClass(cls):
        # only the manager process should be returned by active_children()
        # but this can take a bit on slow machines, so wait a few seconds
        # if there are other children too (see #17395)
        t = 0.01
        while len(multiprocessing.active_children()) > 1 and t < 5:
            time.sleep(t)
            t *= 2
        gc.collect()                       # do garbage collection
        if cls.manager._number_of_objects() != 0:
            # This is not really an error since some tests do not
            # ensure that all processes which hold a reference to a
            # managed object have been joined.
            print('Shared objects which still exist at manager shutdown:')
            print(cls.manager._debug_info())
        cls.manager.shutdown()
        cls.manager.join()
        cls.manager = None 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:_test_multiprocessing.py

示例5: test_server_multiproc

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_server_multiproc(mocker, set_timeout, restore_signal, start_method):

    mpctx = mp.get_context(start_method)
    mocker.patch('aiotools.server.mp', mpctx)

    started = mpctx.Value('i', 0)
    terminated = mpctx.Value('i', 0)
    proc_idxs = mpctx.Array('i', 3)

    set_timeout(0.2, interrupt)
    aiotools.start_server(myserver_multiproc, num_workers=3,
                          args=(started, terminated, proc_idxs))

    assert started.value == 3
    assert terminated.value == 3
    assert list(proc_idxs) == [0, 1, 2]
    assert len(mp.active_children()) == 0 
开发者ID:achimnol,项目名称:aiotools,代码行数:19,代码来源:test_server.py

示例6: test_server_multiproc_custom_stop_signals

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_server_multiproc_custom_stop_signals(
        mocker, set_timeout, restore_signal, start_method):

    mpctx = mp.get_context(start_method)
    mocker.patch('aiotools.server.mp', mpctx)

    started = mpctx.Value('i', 0)
    terminated = mpctx.Value('i', 0)
    received_signals = mpctx.Array('i', 2)
    proc_idxs = mpctx.Array('i', 2)

    set_timeout(0.2, interrupt_usr1)
    aiotools.start_server(myserver_multiproc_custom_stop_signals,
                          num_workers=2,
                          stop_signals={signal.SIGUSR1},
                          args=(started, terminated, received_signals, proc_idxs))

    assert started.value == 2
    assert terminated.value == 2
    assert list(received_signals) == [signal.SIGUSR1, signal.SIGUSR1]
    assert list(proc_idxs) == [0, 1]
    assert len(mpctx.active_children()) == 0 
开发者ID:achimnol,项目名称:aiotools,代码行数:24,代码来源:test_server.py

示例7: test_end_to_end

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_end_to_end(self):
        autosave_file = self.autosave_file
        btcrpass.parse_arguments(self.E2E_ARGS,
                                 tokenlist            = StringIO(self.E2E_TOKENLIST),
                                 exclude_passwordlist = StringIO(self.E2E_EXCLUDELIST),
                                 data_extract         = self.E2E_DATA_EXTRACT,
                                 autosave             = autosave_file)
        self.assertEqual("btcr-test-password", btcrpass.main()[0])
        for process in multiprocessing.active_children():
            process.join()  # wait for any remaining child processes to exit cleanly

        # Verify the exact password number where it was found to ensure password ordering hasn't changed
        autosave_file.seek(SAVESLOT_SIZE)
        savestate = cPickle.load(autosave_file)
        self.assertEqual(savestate.get(b"skip"), 103762)

    # Repeat the test above using the same autosave file, starting off just before the password was found 
开发者ID:gurnec,项目名称:btcrecover,代码行数:19,代码来源:test_passwords.py

示例8: test_skip

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_skip(self):
        autosave_file = BytesIONonClosing()
        btcrpass.parse_arguments(self.E2E_ARGS + [tstr("--skip=103763")],
                                 tokenlist            = StringIO(self.E2E_TOKENLIST),
                                 exclude_passwordlist = StringIO(self.E2E_EXCLUDELIST),
                                 data_extract         = self.E2E_DATA_EXTRACT,
                                 autosave             = autosave_file)
        self.assertIn("Password search exhausted", btcrpass.main()[1])
        for process in multiprocessing.active_children():
            process.join()  # wait for any remaining child processes to exit cleanly

        # Verify the password number where the search started
        autosave_file.seek(0)
        savestate = cPickle.load(autosave_file)
        self.assertEqual(savestate.get(b"skip"), 103763)

        # Verify the total count of passwords
        autosave_file.seek(SAVESLOT_SIZE)
        savestate = cPickle.load(autosave_file)
        self.assertEqual(savestate.get(b"skip"), 139652)


# QuickTests: all of Test01Basics, Test02Anchors, Test03WildCards, and Test04Typos,
# all of Test05CommandLine except the "large" tests, and select quick tests from
# Test08KeyDecryption 
开发者ID:gurnec,项目名称:btcrecover,代码行数:27,代码来源:test_passwords.py

示例9: teardown_test_type

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def teardown_test_type(test_type, runtimes, request_handler):
    from functools import partial
    def wait_for_it(peer):
        while True:
            try:
                request_handler.get_node_id(peer)
            except Exception:
                return True
        return False

    if test_type == "local":
        for peer in runtimes:
            request_handler.quit(peer)
        for peer in runtimes:
            retry(10, partial(wait_for_it, peer), lambda r: r, "Failed to stop peer %r" % (peer,))
        for p in multiprocessing.active_children():
            p.terminate()
            time.sleep(1) 
开发者ID:EricssonResearch,项目名称:calvin-base,代码行数:20,代码来源:helpers.py

示例10: teardown_slow

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def teardown_slow(runtimes, request_handler, hostname):
    request_handler.set_credentials({"user": "user0", "password": "pass0"})
    for i in range(1, len(runtimes)):
        _log.info("kill runtime {}".format(i))
        try:
            request_handler.quit(runtimes[i]["RT"])
        except Exception:
            _log.error("Failed quit for node {}".format(i))
    # Kill Auth/Authz node last since the other nodes need it for authorization
    # of the kill requests
    time.sleep(2)
    try:
        request_handler.quit(runtimes[0]["RT"])
    except Exception:
        _log.error("Failed quit for node 0")
    time.sleep(0.2)
    for p in multiprocessing.active_children():
        p.terminate()
    # They will die eventually (about 5 seconds) in most cases, but this makes sure without wasting time
    for i in range(len(runtimes)):
        os.system("pkill -9 -f 'csruntime -n {} -p 500{}'" .format(hostname,i))
    time.sleep(0.2) 
开发者ID:EricssonResearch,项目名称:calvin-base,代码行数:24,代码来源:helpers.py

示例11: test_issue_480_processes

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_issue_480_processes(self):
        client = self.sync_client
        before = len(multiprocessing.active_children())
        for idx in range(10):
            response = client.api_test()
            self.assertIsNotNone(response)
        after = len(multiprocessing.active_children())
        self.assertEqual(0, after - before) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:10,代码来源:test_issue_480.py

示例12: test_issue_480_processes_async

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_issue_480_processes_async(self):
        client = self.async_client
        before = len(multiprocessing.active_children())
        for idx in range(10):
            response = await client.api_test()
            self.assertIsNotNone(response)
        after = len(multiprocessing.active_children())
        self.assertEqual(0, after - before)

    # fails with Python 3.6 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:12,代码来源:test_issue_480.py

示例13: test_process

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_process(self):
        q = self.Queue(1)
        e = self.Event()
        args = (q, 1, 2)
        kwargs = {'hello':23, 'bye':2.54}
        name = 'SomeProcess'
        p = self.Process(
            target=self._test, args=args, kwargs=kwargs, name=name
            )
        p.daemon = True
        current = self.current_process()

        if self.TYPE != 'threads':
            self.assertEqual(p.authkey, current.authkey)
        self.assertEqual(p.is_alive(), False)
        self.assertEqual(p.daemon, True)
        self.assertNotIn(p, self.active_children())
        self.assertTrue(type(self.active_children()) is list)
        self.assertEqual(p.exitcode, None)

        p.start()

        self.assertEqual(p.exitcode, None)
        self.assertEqual(p.is_alive(), True)
        self.assertIn(p, self.active_children())

        self.assertEqual(q.get(), args[1:])
        self.assertEqual(q.get(), kwargs)
        self.assertEqual(q.get(), p.name)
        if self.TYPE != 'threads':
            self.assertEqual(q.get(), current.authkey)
            self.assertEqual(q.get(), p.pid)

        p.join()

        self.assertEqual(p.exitcode, 0)
        self.assertEqual(p.is_alive(), False)
        self.assertNotIn(p, self.active_children()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:40,代码来源:test_multiprocessing.py

示例14: test_active_children

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_active_children(self):
        self.assertEqual(type(self.active_children()), list)

        p = self.Process(target=time.sleep, args=(DELTA,))
        self.assertNotIn(p, self.active_children())

        p.daemon = True
        p.start()
        self.assertIn(p, self.active_children())

        p.join()
        self.assertNotIn(p, self.active_children()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_multiprocessing.py

示例15: test_number_of_objects

# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import active_children [as 别名]
def test_number_of_objects(self):
        EXPECTED_NUMBER = 1                # the pool object is still alive
        multiprocessing.active_children()  # discard dead process objs
        gc.collect()                       # do garbage collection
        refs = self.manager._number_of_objects()
        debug_info = self.manager._debug_info()
        if refs != EXPECTED_NUMBER:
            print self.manager._debug_info()
            print debug_info

        self.assertEqual(refs, EXPECTED_NUMBER)

#
# Test of creating a customized manager class
# 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_multiprocessing.py


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