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


Python asyncio.Condition方法代码示例

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


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

示例1: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def __init__(self, channel_service: 'ChannelService'):
        self._channel_service = channel_service
        self._block_manager = None
        self._blockchain = None

        self._thread_pool = ThreadPoolExecutor(1, "ChannelInnerThread")

        # Citizen
        CitizenInfo = namedtuple("CitizenInfo", "peer_id target connected_time")
        self._CitizenInfo = CitizenInfo
        self._citizens: Dict[str, CitizenInfo] = dict()
        self._citizen_condition_new_block: Condition = None
        self._citizen_condition_unregister: Condition = None

        self.__sub_processes = []
        self.__loop_for_sub_services = None 
开发者ID:icon-project,项目名称:loopchain,代码行数:18,代码来源:channel_inner_service.py

示例2: test_context_manager_async_with

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def test_context_manager_async_with(self):
        primitives = [
            asyncio.Lock(loop=self.loop),
            asyncio.Condition(loop=self.loop),
            asyncio.Semaphore(loop=self.loop),
            asyncio.BoundedSemaphore(loop=self.loop),
        ]

        async def test(lock):
            await asyncio.sleep(0.01, loop=self.loop)
            self.assertFalse(lock.locked())
            async with lock as _lock:
                self.assertIs(_lock, None)
                self.assertTrue(lock.locked())
                await asyncio.sleep(0.01, loop=self.loop)
                self.assertTrue(lock.locked())
            self.assertFalse(lock.locked())

        for primitive in primitives:
            self.loop.run_until_complete(test(primitive))
            self.assertFalse(primitive.locked()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_pep492.py

示例3: test_context_manager_with_await

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def test_context_manager_with_await(self):
        primitives = [
            asyncio.Lock(loop=self.loop),
            asyncio.Condition(loop=self.loop),
            asyncio.Semaphore(loop=self.loop),
            asyncio.BoundedSemaphore(loop=self.loop),
        ]

        async def test(lock):
            await asyncio.sleep(0.01, loop=self.loop)
            self.assertFalse(lock.locked())
            with await lock as _lock:
                self.assertIs(_lock, None)
                self.assertTrue(lock.locked())
                await asyncio.sleep(0.01, loop=self.loop)
                self.assertTrue(lock.locked())
            self.assertFalse(lock.locked())

        for primitive in primitives:
            self.loop.run_until_complete(test(primitive))
            self.assertFalse(primitive.locked()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_pep492.py

示例4: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def __init__(self, minsize, maxsize, echo, loop, pool_recycle, **kwargs):
        if minsize < 0:
            raise ValueError("minsize should be zero or greater")
        if maxsize < minsize:
            raise ValueError("maxsize should be not less than minsize")
        self._minsize = minsize
        self._loop = loop
        self._conn_kwargs = kwargs
        self._acquiring = 0
        self._recycle = pool_recycle
        self._free = collections.deque(maxlen=maxsize)
        self._cond = asyncio.Condition(loop=loop)
        self._used = set()
        self._closing = False
        self._closed = False
        self._echo = echo 
开发者ID:aio-libs,项目名称:aioodbc,代码行数:18,代码来源:pool.py

示例5: print_tests

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def print_tests():
    st = '''Available functions:
print_tests()  Print this list.
ack_test()  Test event acknowledge and Message class.
message_test() Test Message class.
event_test()  Test Event and Lock objects.
barrier_test()  Test the Barrier class.
semaphore_test(bounded=False)  Test Semaphore or BoundedSemaphore.
condition_test()  Test the Condition class.
queue_test()  Test the  Queue class

Recommended to issue ctrl-D after running each test.
'''
    print('\x1b[32m')
    print(st)
    print('\x1b[39m') 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:18,代码来源:prim_test.py

示例6: cond_go

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def cond_go():
    cond = asyncio.Condition()
    ntasks = 7
    barrier = Barrier(ntasks + 1)
    t1 = asyncio.create_task(cond01_new(cond))
    t3 = asyncio.create_task(cond03_new())
    for n in range(ntasks):
        asyncio.create_task(cond02(n, cond, barrier))
    await barrier  # All instances of cond02 have completed
    # Test wait_for
    barrier = Barrier(2)
    asyncio.create_task(cond04(99, cond, barrier))
    await barrier
    # cancel continuously running coros.
    t1.cancel()
    t3.cancel()
    await asyncio.sleep(0)
    print('Done.') 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:20,代码来源:prim_test.py

示例7: _get_condition

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def _get_condition(self):
        """
        Creation of condition is delayed, to minimize the change of using the
        wrong loop.

        A user may create a mock with _AwaitEvent before selecting the
        execution loop.  Requiring a user to delay creation is error-prone and
        inflexible. Instead, condition is created when user actually starts to
        use the mock.
        """
        # No synchronization is needed:
        #   - asyncio is thread unsafe
        #   - there are no awaits here, method will be executed without
        #   switching asyncio context.
        if self._condition is None:
            self._condition = asyncio.Condition()

        return self._condition 
开发者ID:Martiusweb,项目名称:asynctest,代码行数:20,代码来源:mock.py

示例8: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def __init__(self, service, name=None, executor=None):
        super().__init__(service, name)
        self._state = State.CREATE

        # A Task may want to run blocking calls in separate thread. To run a
        # method in separate thread, task can use the _run_in_executor() method.
        # User can create their own executor instead using the default one
        # created by the asyncio. This allows user control over the type of
        # executor (task/threads) and its properties (e.g. num_workers)
        self._executor = executor

        # _update_event can be used to notify coroutines about the change in
        # state in this service. e.g. run() has completed
        self._update_event = asyncio.Condition(loop=self.loop)

        self.set_state(State.INIT)

        coro = self.start()
        # fixup task name to show actual task in logs
        coro.__qualname__ = self._objname
        self._task = asyncio.ensure_future(coro, loop=self.loop)

        self._ALL_TASKS[self._objname] = self 
开发者ID:facebookincubator,项目名称:FCR,代码行数:25,代码来源:base_service.py

示例9: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def __init__(self, dsn, minsize, maxsize, timeout, *,
                 enable_json, enable_hstore, enable_uuid, echo,
                 on_connect, pool_recycle, **kwargs):
        if minsize < 0:
            raise ValueError("minsize should be zero or greater")
        if maxsize < minsize and maxsize != 0:
            raise ValueError("maxsize should be not less than minsize")
        self._dsn = dsn
        self._minsize = minsize
        self._loop = get_running_loop(kwargs.pop('loop', None) is not None)
        self._timeout = timeout
        self._recycle = pool_recycle
        self._enable_json = enable_json
        self._enable_hstore = enable_hstore
        self._enable_uuid = enable_uuid
        self._echo = echo
        self._on_connect = on_connect
        self._conn_kwargs = kwargs
        self._acquiring = 0
        self._free = collections.deque(maxlen=maxsize or None)
        self._cond = asyncio.Condition(loop=self._loop)
        self._used = set()
        self._terminated = set()
        self._closing = False
        self._closed = False 
开发者ID:aio-libs,项目名称:aiopg,代码行数:27,代码来源:pool.py

示例10: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def __init__(self, server_state, fetch_chunk_size=0, capabilities=CAPABILITIES,
                 loop=asyncio.get_event_loop()):
        self.uidvalidity = int(datetime.now().timestamp())
        self.capabilities = capabilities
        self.state_to_send = list()
        self.delay_seconds = 0
        self.loop = loop
        self.fetch_chunk_size = fetch_chunk_size
        self.transport = None
        self.server_state = server_state
        self.user_login = None
        self.user_mailbox = None
        self.idle_tag = None
        self.idle_task = None
        self.state = NONAUTH
        self.state_condition = asyncio.Condition()
        self.append_literal_command = None 
开发者ID:bamthomas,项目名称:aioimaplib,代码行数:19,代码来源:imapserver.py

示例11: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def __init__(self, loop, conn_lost_cb=None):
        self.loop = loop
        self.transport = None
        self.state = STARTED
        self.state_condition = asyncio.Condition()
        self.capabilities = set()
        self.pending_async_commands = dict()
        self.pending_sync_command = None
        self.idle_queue = asyncio.Queue()
        self.imap_version = None
        self.literal_data = None
        self.incomplete_line = b''
        self.current_command = None
        self.conn_lost_cb = conn_lost_cb

        self.tagnum = 0
        self.tagpre = int2ap(random.randint(4096, 65535)) 
开发者ID:bamthomas,项目名称:aioimaplib,代码行数:19,代码来源:aioimaplib.py

示例12: main

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def main(loop):
    # Create a condition
    condition = asyncio.Condition()

    # Set up tasks watching the condition
    consumers = [
        consumer(condition, i)
        for i in range(5)
    ]

    # Schedule a task to manipulate the condition variable
    loop.create_task(manipulate_condition(condition))

    # Wait for the consumers to be done
    await asyncio.wait(consumers) 
开发者ID:PacktPublishing,项目名称:Learning-Concurrency-in-Python,代码行数:17,代码来源:asyncioCondition.py

示例13: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def __init__(self, address, db=None, password=None, encoding=None,
                 *, minsize, maxsize, ssl=None, parser=None,
                 create_connection_timeout=None,
                 connection_cls=None,
                 loop=None):
        assert isinstance(minsize, int) and minsize >= 0, (
            "minsize must be int >= 0", minsize, type(minsize))
        assert maxsize is not None, "Arbitrary pool size is disallowed."
        assert isinstance(maxsize, int) and maxsize > 0, (
            "maxsize must be int > 0", maxsize, type(maxsize))
        assert minsize <= maxsize, (
            "Invalid pool min/max sizes", minsize, maxsize)
        if loop is not None and sys.version_info >= (3, 8):
            warnings.warn("The loop argument is deprecated",
                          DeprecationWarning)
        self._address = address
        self._db = db
        self._password = password
        self._ssl = ssl
        self._encoding = encoding
        self._parser_class = parser
        self._minsize = minsize
        self._create_connection_timeout = create_connection_timeout
        self._pool = collections.deque(maxlen=maxsize)
        self._used = set()
        self._acquiring = 0
        self._cond = asyncio.Condition(lock=Lock())
        self._close_state = CloseEvent(self._do_close)
        self._pubsub_conn = None
        self._connection_cls = connection_cls 
开发者ID:aio-libs,项目名称:aioredis,代码行数:32,代码来源:pool.py

示例14: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def __init__(self):
            """Initialize state."""
            self.value = 0
            self.active = False
            self.condition = asyncio.Condition()
            self.tag_sequence = [] 
开发者ID:genialis,项目名称:resolwe,代码行数:8,代码来源:dispatcher.py

示例15: __init__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import Condition [as 别名]
def __init__(self, address, db=0, password=0, encoding=None,
                 *, minsize, maxsize, commands_factory, ssl=None, loop=None):
        if loop is not None and sys.version_info >= (3, 8):
            warnings.warn("The loop argument is deprecated",
                          DeprecationWarning)
        if loop is None and sys.version_info < (3, 8):
            loop = asyncio.get_event_loop()

        self._address = address
        self._db = db
        self._password = password
        self._encoding = encoding
        self._minsize = minsize
        self._maxsize = maxsize
        self._factory = commands_factory
        self._ssl = ssl
        self._loop = loop

        # fake it here, we always only have one connection
        self._pool = collections.deque(maxlen=1)
        self._used = set()
        self._acquiring = 0

        self._cond = asyncio.Condition(loop=loop)
        self._close_state = asyncio.Event(loop=loop)
        self._close_waiter = asyncio.ensure_future(self._do_close(), loop=loop) 
开发者ID:kblin,项目名称:mockaioredis,代码行数:28,代码来源:pool.py


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