Python asyncio.sleep_ms() Examples
The following are 30
code examples of asyncio.sleep_ms().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
asyncio
, or try the search function
.
Example #1
Source File: asyntest.py From micropython-samples with MIT License | 6 votes |
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.')
Example #2
Source File: asyn.py From microhomie with MIT License | 6 votes |
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.
Example #3
Source File: asyntest.py From micropython-async with MIT License | 6 votes |
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.')
Example #4
Source File: asyn.py From micropython-mqtt with MIT License | 6 votes |
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.
Example #5
Source File: specter.py From specter-diy with MIT License | 6 votes |
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()
Example #6
Source File: asyn.py From micropython-async with MIT License | 5 votes |
def acquire(self): while True: if self._locked: await asyncio.sleep_ms(self.delay_ms) else: self._locked = True break
Example #7
Source File: qr.py From specter-diy with MIT License | 5 votes |
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
Example #8
Source File: asyn.py From microhomie with MIT License | 5 votes |
def __await__(self): while not self._flag: await asyncio.sleep_ms(self.delay_ms)
Example #9
Source File: asyn.py From microhomie with MIT License | 5 votes |
def wait(self): # CPython comptaibility while not self._flag: await asyncio.sleep_ms(self.delay_ms)
Example #10
Source File: asyn.py From microhomie with MIT License | 5 votes |
def acquire(self): while True: if self._locked: await asyncio.sleep_ms(self.delay_ms) else: self._locked = True break
Example #11
Source File: qr.py From specter-diy with MIT License | 5 votes |
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
Example #12
Source File: asyntest.py From micropython-async with MIT License | 5 votes |
def bart(): barrier = Barrier(4, my_coro, ('my_coro running',)) for x in range(3): asyncio.create_task(report1(barrier, x)) await barrier # Must yield before reading result(). Here we wait long enough for await asyncio.sleep_ms(1500) # coro to print barrier.result().cancel() await asyncio.sleep(2)
Example #13
Source File: asyntest.py From micropython-async with MIT License | 5 votes |
def my_coro(text): try: await asyncio.sleep_ms(0) while True: await asyncio.sleep(1) print(text) except asyncio.CancelledError: print('my_coro was cancelled.')
Example #14
Source File: message.py From micropython-async with MIT License | 5 votes |
def __await__(self): while not self._flag: await asyncio.sleep_ms(self.delay_ms)
Example #15
Source File: message.py From micropython-async with MIT License | 5 votes |
def wait(self): # CPython comptaibility while not self._flag: await asyncio.sleep_ms(self.delay_ms)
Example #16
Source File: asyn.py From micropython-async with MIT License | 5 votes |
def acquire(self): while self._count == 0: await asyncio.sleep_ms(0) self._count -= 1
Example #17
Source File: asyn.py From micropython-async with MIT License | 5 votes |
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)
Example #18
Source File: asyn.py From micropython-async with MIT License | 5 votes |
def __await__(self): while not self._flag: await asyncio.sleep_ms(self.delay_ms)
Example #19
Source File: asyn.py From micropython-async with MIT License | 5 votes |
def wait(self): # CPython comptaibility while not self._flag: await asyncio.sleep_ms(self.delay_ms)
Example #20
Source File: async_gui.py From specter-diy with MIT License | 5 votes |
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()
Example #21
Source File: semaphore.py From micropython-samples with MIT License | 5 votes |
def acquire(self): while self._count == 0: await asyncio.sleep_ms(0) self._count -= 1
Example #22
Source File: qr.py From specter-diy with MIT License | 5 votes |
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
Example #23
Source File: message.py From micropython-samples with MIT License | 5 votes |
def __await__(self): while not self._flag: await asyncio.sleep_ms(self.delay_ms)
Example #24
Source File: message.py From micropython-samples with MIT License | 5 votes |
def wait(self): # CPython comptaibility while not self._flag: await asyncio.sleep_ms(self.delay_ms)
Example #25
Source File: barrier.py From micropython-samples with MIT License | 5 votes |
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)
Example #26
Source File: server.py From micropython-iot with MIT License | 5 votes |
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__()
Example #27
Source File: core.py From specter-diy with MIT License | 5 votes |
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)
Example #28
Source File: asyn.py From micropython-mqtt with MIT License | 5 votes |
def acquire(self): while True: if self._locked: await asyncio.sleep_ms(self.delay_ms) else: self._locked = True break
Example #29
Source File: core.py From specter-diy with MIT License | 5 votes |
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
Example #30
Source File: screen.py From specter-diy with MIT License | 5 votes |
def result(self): self.waiting = True while self.waiting: await asyncio.sleep_ms(10) return self.get_value()