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


Python futures.ALL_COMPLETED属性代码示例

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


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

示例1: _close_input_devices

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def _close_input_devices(self):
        if not hasattr(self, '_opened') or not self._opened:
            return

        self._opened = False

        for event_device in self._event_devices:
            asyncio.get_event_loop().remove_reader(event_device.fileno())
            event_device.close()

        tasks = []
        for task in self._tasks:
            if not task.done():
                task.cancel()
                tasks.append(task)

        await asyncio.wait(tasks, return_when=futures.ALL_COMPLETED)
        self._event_devices.clear() 
开发者ID:cyanogen,项目名称:uchroma,代码行数:20,代码来源:input.py

示例2: stop

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def stop(self):
        if self.renderer.running:

            tasks = []
            if self.task is not None and not self.task.done():
                self.task.cancel()
                tasks.append(self.task)

            if self.waiter is not None and not self.waiter.done():
                self.waiter.cancel()
                tasks.append(self.waiter)

            await self.renderer._stop()

            if tasks:
                await asyncio.wait(tasks, return_when=futures.ALL_COMPLETED)

            self.renderer.finish(self._frame) 
开发者ID:cyanogen,项目名称:uchroma,代码行数:20,代码来源:anim.py

示例3: _stop

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def _stop(self):
        """
        Stop this AnimationLoop

        Shuts down the loop and triggers cleanup tasks.
        """
        if not self.running:
            return False

        self.running = False

        for layer in self.layers[::-1]:
            await self.remove_layer(layer)

        if self._anim_task is not None and not self._anim_task.done():
            self._anim_task.cancel()
            await asyncio.wait([self._anim_task], return_when=futures.ALL_COMPLETED)

        self._logger.info("AnimationLoop stopped") 
开发者ID:cyanogen,项目名称:uchroma,代码行数:21,代码来源:anim.py

示例4: test_all_completed

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def test_all_completed(self):
        future1 = self.executor.submit(divmod, 2, 0)
        future2 = self.executor.submit(mul, 2, 21)

        finished, pending = futures.wait(
                [SUCCESSFUL_FUTURE,
                 CANCELLED_AND_NOTIFIED_FUTURE,
                 EXCEPTION_FUTURE,
                 future1,
                 future2],
                return_when=futures.ALL_COMPLETED)

        self.assertEqual(set([SUCCESSFUL_FUTURE,
                              CANCELLED_AND_NOTIFIED_FUTURE,
                              EXCEPTION_FUTURE,
                              future1,
                              future2]), finished)
        self.assertEqual(set(), pending) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_concurrent_futures.py

示例5: test_timeout

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def test_timeout(self):
        future1 = self.executor.submit(mul, 6, 7)
        future2 = self.executor.submit(time.sleep, 6)

        finished, pending = futures.wait(
                [CANCELLED_AND_NOTIFIED_FUTURE,
                 EXCEPTION_FUTURE,
                 SUCCESSFUL_FUTURE,
                 future1, future2],
                timeout=5,
                return_when=futures.ALL_COMPLETED)

        self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
                              EXCEPTION_FUTURE,
                              SUCCESSFUL_FUTURE,
                              future1]), finished)
        self.assertEqual(set([future2]), pending) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_concurrent_futures.py

示例6: create_pool

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def create_pool(self, job, parameters, workers=None):
        """ Create resources in pool in sub processes.

        :param workers:
        :type parameters: iterable
        :type job: func
        """
        executor = ThreadPoolExecutor(
            workers) if workers else ThreadPoolExecutor()
        try:
            # futures = [executor.submit(func, i, kwargs) for i in args]
            futures = []
            for param_chunk in parameters:
                param_chunk['self'] = self
                futures.append(executor.submit(job, param_chunk))
            concurrent.futures.wait(futures, return_when=ALL_COMPLETED)
            responses = {}
            for future in futures:
                result = future.result()
                if result:
                    responses.update(result)
            return responses
        finally:
            executor.shutdown(wait=True) 
开发者ID:epam,项目名称:aws-syndicate,代码行数:26,代码来源:base_resource.py

示例7: assemble_python_lambdas

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def assemble_python_lambdas(project_path, bundles_dir):
    from syndicate.core import CONFIG
    project_base_folder = os.path.basename(os.path.normpath(project_path))
    project_abs_path = build_path(CONFIG.project_path, project_path)
    _LOG.info('Going to process python project by path: {0}'.format(
        project_abs_path))
    executor = ThreadPoolExecutor(max_workers=5)
    futures = []
    for root, sub_dirs, files in os.walk(project_abs_path):
        for item in files:
            if item.endswith(LAMBDA_CONFIG_FILE_NAME):
                _LOG.info('Going to build artifact in: {0}'.format(root))
                arg = {
                    'item': item,
                    'project_base_folder': project_base_folder,
                    'project_path': project_path,
                    'root': root,
                    'target_folder': bundles_dir
                }
                futures.append(executor.submit(_build_python_artifact, arg))
    concurrent.futures.wait(futures, return_when=ALL_COMPLETED)
    executor.shutdown()
    _LOG.info('Python project was processed successfully') 
开发者ID:epam,项目名称:aws-syndicate,代码行数:25,代码来源:python.py

示例8: sed_msg

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def sed_msg(mobile, set_of_times, interval_time, remainder):
    init_mobile(mobile, set_of_times)
    available_msg = []
    while len(available_msg) < remainder:
        m = random.choice(all_message_info)
        if check_available(m):
            available_msg.append(m)
    pool = ThreadPoolExecutor(500)
    SHARE_Q = queue.Queue(remainder)
    while SHARE_Q.qsize() < remainder:
        SHARE_Q.put(random.choice(available_msg))
    all_task = []
    for t in range(SHARE_Q.qsize()):
        mg = SHARE_Q.get()
        try:
            all_task.append(pool.submit(eval(mg), mg, mobile))
        except KeyboardInterrupt:
            r.delete('%s_%d' % (mobile, set_of_times))
            sys.exit(0)
        if interval_time:
            time.sleep(interval_time)
    wait(all_task, return_when=ALL_COMPLETED) 
开发者ID:Brightest08,项目名称:message,代码行数:24,代码来源:message_main.py

示例9: _create_and_install_waiters

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def _create_and_install_waiters(fs, return_when):
        if return_when == _AS_COMPLETED:
            waiter = _AsCompletedWaiter()
        elif return_when == FIRST_COMPLETED:
            waiter = _FirstCompletedWaiter()
        else:
            pending_count = sum(
                    f._state not in [CANCELLED_AND_NOTIFIED, FINISHED]
                    for f in fs)

            if return_when == FIRST_EXCEPTION:
                waiter = _AllCompletedWaiter(pending_count,
                                             stop_on_exception=True)
            elif return_when == ALL_COMPLETED:
                waiter = _AllCompletedWaiter(pending_count,
                                             stop_on_exception=False)
            else:
                raise ValueError("Invalid return condition: %r" % return_when)

        for f in fs:
            f._waiters.append(waiter)

        return waiter 
开发者ID:joblib,项目名称:loky,代码行数:25,代码来源:_base.py

示例10: test_timeout

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def test_timeout(self):
        # Make sure the executor has already started to avoid timeout happening
        # before future1 returns
        assert self.executor.submit(id_sleep, 42).result() == 42

        future1 = self.executor.submit(mul, 6, 7)
        future2 = self.executor.submit(self.wait_and_return, 5)

        assert future1.result() == 42

        finished, pending = futures.wait([CANCELLED_AND_NOTIFIED_FUTURE,
                                          EXCEPTION_FUTURE, SUCCESSFUL_FUTURE,
                                          future1, future2],
                                         timeout=.1,
                                         return_when=futures.ALL_COMPLETED)

        assert set([CANCELLED_AND_NOTIFIED_FUTURE, EXCEPTION_FUTURE,
                    SUCCESSFUL_FUTURE, future1]) == finished
        assert set([future2]) == pending

        _executor_mixin._test_event.set()
        assert future2.result(timeout=10)
        _executor_mixin._test_event.clear() 
开发者ID:joblib,项目名称:loky,代码行数:25,代码来源:_test_process_executor.py

示例11: discover

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def discover(self, timeout=None):    # TODO: better name?
        """Discover sentinels and all monitored services within given timeout.

        If no sentinels discovered within timeout: TimeoutError is raised.
        If some sentinels were discovered but not all — it is ok.
        If not all monitored services (masters/slaves) discovered
        (or connections established) — it is ok.
        TBD: what if some sentinels/services unreachable;
        """
        # TODO: check not closed
        # TODO: discovery must be done with some customizable timeout.
        if timeout is None:
            timeout = self.discover_timeout
        tasks = []
        pools = []
        for addr in self._sentinels:    # iterate over unordered set
            tasks.append(self._connect_sentinel(addr, timeout, pools))
        done, pending = await asyncio.wait(tasks,
                                           return_when=ALL_COMPLETED)
        assert not pending, ("Expected all tasks to complete", done, pending)

        for task in done:
            result = task.result()
            if isinstance(result, Exception):
                continue    # FIXME
        if not pools:
            raise Exception("Could not connect to any sentinel")
        pools, self._pools[:] = self._pools[:], pools
        # TODO: close current connections
        for pool in pools:
            pool.close()
            await pool.wait_closed()

        # TODO: discover peer sentinels
        for pool in self._pools:
            await pool.execute_pubsub(
                b'psubscribe', self._monitor.pattern('*')) 
开发者ID:aio-libs,项目名称:aioredis,代码行数:39,代码来源:pool.py

示例12: wait_tasks

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def wait_tasks(futures, timeout=None, return_when=ALL_COMPLETED, raise_exceptions=True):
        running_futures = [fut for fut in futures if not fut.done()]
        done, _ = wait(running_futures, timeout=timeout, return_when=return_when)
        if raise_exceptions:
            [f.result() for f in done if not f.cancelled() and f.exception() is not None]  # raises the exception 
开发者ID:man-group,项目名称:arctic,代码行数:7,代码来源:_workers_pool.py

示例13: wait_tasks_or_abort

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def wait_tasks_or_abort(futures, timeout=60, kill_switch_ev=None):
        try:
            LazySingletonTasksCoordinator.wait_tasks(futures, return_when=FIRST_EXCEPTION, raise_exceptions=True)
        except Exception as e:
            if kill_switch_ev is not None:
                # Used when we want to keep both raise the exception and wait for all tasks to finish
                kill_switch_ev.set()
                LazySingletonTasksCoordinator.wait_tasks(futures, return_when=ALL_COMPLETED,
                                                         raise_exceptions=False, timeout=timeout)
            raise e 
开发者ID:man-group,项目名称:arctic,代码行数:12,代码来源:_workers_pool.py

示例14: await_termination

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def await_termination(self, timeout=None):
        with type(self)._POOL_LOCK:
            if not self.is_shutdown:
                raise AsyncArcticException("The workers pool has not been shutdown, please call shutdown() first.")
        LazySingletonTasksCoordinator.wait_tasks(
            [v[0] for v in itervalues(self.alive_tasks)],
            timeout=timeout, return_when=ALL_COMPLETED, raise_exceptions=False)
        with type(self)._POOL_LOCK:
            self.alive_tasks = {} 
开发者ID:man-group,项目名称:arctic,代码行数:11,代码来源:_workers_pool.py

示例15: _run

# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import ALL_COMPLETED [as 别名]
def _run(self):
        dm = UChromaDeviceManager()

        atexit.register(UChromaServer.exit, self._loop)

        dbus = DeviceManagerAPI(dm, self._logger)
        power = PowerMonitor()

        for sig in (signal.SIGINT, signal.SIGTERM):
            self._loop.add_signal_handler(sig, self._shutdown_callback)

        try:
            dbus.run()
            power.start()

            ensure_future(dm.monitor_start(), loop=self._loop)

            self._loop.run_forever()

        except KeyboardInterrupt:
            pass

        finally:
            for sig in (signal.SIGTERM, signal.SIGINT):
                self._loop.remove_signal_handler(sig)

            power.stop()

            self._loop.run_until_complete(asyncio.wait( \
                    [dm.close_devices(), dm.monitor_stop()],
                    return_when=futures.ALL_COMPLETED)) 
开发者ID:cyanogen,项目名称:uchroma,代码行数:33,代码来源:server.py


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