當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。