示例#1
0
    def set(self, timeout_ms: int, callback: IdleCallback) -> None:
        """Add or update an idle callback.

        Every time `timeout_ms` milliseconds elapse after the last registered activity,
        `callback` will be invoked.
        I.e., in every period of inactivity, each `callback` will only run once. To run
        again, an activity must be registered and then no activity for the specified
        period.

        If `callback` was previously registered, it is updated with a new timeout value.

        `idle_timer.set()` also counts as an activity, so all running idle timers are
        reset.
        """
        # The reason for counting set() as an activity is to clear up an ambiguity that
        # would arise otherwise. This does not matter now, as callbacks are only
        # scheduled during periods of activity.
        # If we ever need to add a callback without touching, we will need to know
        # when this callback should execute (10 mins from now? from last activity? if
        # the latter, what if 10 minutes have already elapsed?)
        if callback in self.tasks:
            loop.close(self.tasks[callback])

        self.timeouts[callback] = timeout_ms
        self.tasks[callback] = self._timeout_task(callback)
        self.touch()
示例#2
0
def closedefault():
    global default

    if default:
        loop.close(default)
        default = None
        log.debug(__name__, 'closedefault')
示例#3
0
def close_default() -> None:
    """Explicitly close the default workflow task."""
    global default_task

    if default_task:
        loop.close(default_task)
        default_task = None
示例#4
0
def close_default() -> None:
    """Explicitly close the default workflow task."""
    if default_task:
        if __debug__:
            log.debug(__name__, "close default")
        # We let the `_finalize_default` reset the global.
        loop.close(default_task)
示例#5
0
 def compare(self, action: int, checksum: bytes) -> bool:
     if self.action != action or self.checksum != checksum:
         return False
     if utime.ticks_ms() >= self.deadline:
         if self.workflow is not None:
             loop.close(self.workflow)
         return False
     return True
示例#6
0
 async def inner(*args, **kwargs):
     await backlight_slide(BACKLIGHT_DIM, delay, step)
     slide = backlight_slide(BACKLIGHT_NORMAL, delay, step)
     try:
         loop.schedule(slide)
         return await f(*args, **kwargs)
     finally:
         loop.close(slide)
示例#7
0
 def compare(self, action: int, checksum: bytes) -> bool:
     if self.action != action or self.checksum != checksum:
         return False
     if utime.ticks_ms() >= self.deadline:
         if self.workflow is not None:
             # We crossed the deadline, kill the running confirmation
             # workflow. `self.workflow` is reset in the finally
             # handler in `confirm_workflow`.
             loop.close(self.workflow)
         return False
     return True
示例#8
0
 async def inner(*args, **kwargs):
     await backlight_slide(BACKLIGHT_DIM)
     slide = backlight_slide(BACKLIGHT_NORMAL)
     try:
         layout = f(*args, **kwargs)
         workflow.onlayoutstart(layout)
         loop.schedule(slide)
         return await layout
     finally:
         loop.close(slide)
         workflow.onlayoutclose(layout)
示例#9
0
    def setup(self, action: int, checksum: bytes, app_id: bytes) -> None:
        if self.workflow is not None:
            loop.close(self.workflow)
        if workflow.workflows:
            return False

        self.action = action
        self.checksum = checksum
        self.app_id = app_id

        self.confirmed = None
        self.workflow = self.confirm_workflow()
        loop.schedule(self.workflow)
        return True
示例#10
0
def kill_default() -> None:
    """Forcefully shut down default task.

    The purpose of the call is to prevent the default task from interfering with
    a synchronous layout-less workflow (e.g., the progress bar in `mnemonic.get_seed`).

    This function should only be called from a workflow registered with `on_start`.
    Otherwise the default will be restarted immediately.
    """
    if default_task:
        if __debug__:
            log.debug(__name__, "close default")
        # We let the `_finalize_default` reset the global.
        loop.close(default_task)
示例#11
0
 def remove(self, callback: IdleCallback) -> None:
     """Remove an idle callback."""
     self.timeouts.pop(callback, None)
     task = self.tasks.pop(callback, None)
     if task is not None:
         loop.close(task)
示例#12
0
 def kill(self) -> None:
     if self.task is not None:
         workflow.onclose(self.task)
         loop.close(self.task)
         self.task = None
示例#13
0
def closedefault():
    global default

    if default:
        loop.close(default)
        default = None
示例#14
0
 def close(self, sid):
     if sid in self.handling_tasks:
         task = self.handling_tasks.pop(sid)
         loop.close(task)
示例#15
0
 def kill(self) -> None:
     if self.task is not None:
         loop.close(self.task)
         self.task = None
示例#16
0
def close_default() -> None:
    """Explicitly close the default workflow task."""
    if default_task:
        # We let the `_finalize_default` reset the global.
        loop.close(default_task)