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


Python asyncio.sleep_ms方法代码示例

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


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

示例1: coro

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def coro(self, host, scr):
        """
        Waits for one of two events:
        - either user presses something on the screen
        - or host finishes processing
        Also updates progress screen
        """
        while host.in_progress and scr.waiting:
            await asyncio.sleep_ms(30)
            scr.tick(5)
            scr.set_progress(host.progress)
        if host.in_progress:
            host.abort()
        if scr.waiting:
            scr.waiting = False
        await self.close_popup() 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:18,代码来源:specter.py

示例2: sleep

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def sleep(t, granularity=100):  # 100ms default
    if granularity <= 0:
        raise ValueError('sleep granularity must be > 0')
    t = int(t * 1000)  # ms
    if t <= granularity:
        await asyncio.sleep_ms(t)
    else:
        n, rem = divmod(t, granularity)
        for _ in range(n):
            await asyncio.sleep_ms(granularity)
        await asyncio.sleep_ms(rem)

# Anonymous cancellable tasks. These are members of a group which is identified
# by a user supplied name/number (default 0). Class method cancel_all() cancels
# all tasks in a group and awaits confirmation. Confirmation of ending (whether
# normally or by cancellation) is signalled by a task calling the _stopped()
# class method. Handled by the @cancellable decorator. 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:19,代码来源:asyn.py

示例3: cond_go

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

示例4: query

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def query(self, data, timeout=100):
        """Blocking query"""
        self.uart.write(data)
        t0 = time.time()
        while self.uart.any() < 7:
            time.sleep_ms(10)
            t = time.time()
            if t > t0+timeout/1000:
                return None
        res = self.uart.read(7)
        return res 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:13,代码来源:qr.py

示例5: scan

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def scan(self):
        self.clean_uart()
        if self.trigger is not None:
            self.trigger.off()
        else:
            self.set_setting(SETTINGS_ADDR, SETTINGS_CONT_MODE)
        self.data = b""
        self.scanning = True
        self.animated = False
        while self.scanning:
            await asyncio.sleep_ms(10)
            # we will exit this loop from update() 
            # or manual cancel from GUI
        return self.data 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:16,代码来源:qr.py

示例6: update

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def update(self):
        if not self.scanning:
            self.clean_uart()
            return
        # read all available data
        if self.uart.any() > 0:
            d = self.uart.read()
            self.data += d
            # we got a full scan
            if self.data.endswith(self.EOL):
                # maybe two
                chunks = self.data.split(self.EOL)
                self.data = b""
                try:
                    for chunk in chunks[:-1]:
                        if self.process_chunk(chunk):
                            self.stop_scanning()
                            break
                        # animated in trigger mode
                        elif self.trigger is not None:
                            self.trigger.on()
                            await asyncio.sleep_ms(30)
                            self.trigger.off()
                except Exception as e:
                    print(e)
                    self.stop_scanning()
                    raise e 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:29,代码来源:qr.py

示例7: update_loop

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def update_loop(self, dt:int):
        while not self.enabled:
            await asyncio.sleep_ms(100)
        while True:
            if self.enabled:
                try:
                    await self.update()
                except Exception as e:
                    self.abort()
                    if self.manager is not None:
                        await self.manager.host_exception_handler(e)
            # Keep await sleep here
            # It allows other functions to run
            await asyncio.sleep_ms(dt) 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:16,代码来源:core.py

示例8: enable

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def enable(self):
        """
        What should happen when host enables?
        Maybe you want to remove all pending data first?
        """
        if not self.initialized:
            self.init()
            await asyncio.sleep_ms(self.RECOVERY_TIME)
            self.initialized = True
        self.enabled = True 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:12,代码来源:core.py

示例9: load_screen

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def load_screen(self, scr):
        while self.background is not None:
            await asyncio.sleep_ms(10)
        old_scr = lv.scr_act()
        lv.scr_load(scr)
        self.scr = scr
        old_scr.del_async() 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:9,代码来源:async_gui.py

示例10: open_popup

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def open_popup(self, scr):
        # wait for another popup to finish
        while self.background is not None:
            await asyncio.sleep_ms(10)
        self.background = self.scr
        self.scr = scr
        lv.scr_load(scr) 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:9,代码来源:async_gui.py

示例11: update_loop

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def update_loop(self, dt):
        while True:
            update(dt)
            await asyncio.sleep_ms(dt) 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:6,代码来源:async_gui.py

示例12: result

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def result(self):
        self.waiting = True
        while self.waiting:
            await asyncio.sleep_ms(10)
        return self.get_value() 
开发者ID:cryptoadvance,项目名称:specter-diy,代码行数:7,代码来源:screen.py

示例13: acquire

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def acquire(self):
        while True:
            if self._locked:
                await asyncio.sleep_ms(self.delay_ms)
            else:
                self._locked = True
                break 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:9,代码来源:asyn.py

示例14: __await__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def __await__(self):
        if upython:
            while not self():
                yield from asyncio.sleep_ms(self._tim_short_ms)
        else: 
            # CPython: Meet requirement for generator in __await__
            # https://github.com/python/asyncio/issues/451
            yield from self._status_coro().__await__() 
开发者ID:peterhinch,项目名称:micropython-iot,代码行数:10,代码来源:server.py

示例15: __await__

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import sleep_ms [as 别名]
def __await__(self):
        self._update()
        if self._at_limit():  # All other threads are also at limit
            if self._func is not None:
                launch(self._func, self._args)
            self._reset(not self._down)  # Toggle direction to release others
            return

        direction = self._down
        while True:  # Wait until last waiting thread changes the direction
            if direction != self._down:
                return
            await asyncio.sleep_ms(0) 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:15,代码来源:barrier.py


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