コード例 #1
0
ファイル: asyncoro.py プロジェクト: MurtAlsa/mpyc
    def typed_asyncoro(*args, **kwargs):
        runtime._pc_level += 1
        coro = func(*args, **kwargs)
        if rettype:
            decl = returnType(rettype, wrap=False)
        else:
            try:
                decl = coro.send(None)
            except StopIteration as exc:
                runtime._pc_level -= 1
                return exc.value

            except Exception:
                runtime._pc_level -= 1
                raise

        if runtime.options.no_async:
            while True:
                try:
                    coro.send(None)
                except StopIteration as exc:
                    runtime._pc_level -= 1
                    if decl is not None:
                        __reconcile(decl, exc.value)
                    return decl

                except Exception:
                    runtime._pc_level -= 1
                    raise

        if pc:
            coro = _wrap_in_coro(_ProgramCounterWrapper(runtime, coro))
        task = Task(coro, loop=runtime._loop)
        task.add_done_callback(lambda t: _reconcile(decl, t))
        return _ncopy(decl)
コード例 #2
0
ファイル: server.py プロジェクト: MaxwellRebo/cess
    def _accept_client(self, client_reader, client_writer):
        """manage new client connections"""
        task = Task(self._handle_client(client_reader, client_writer))
        self.clients[task] = (client_reader, client_writer)

        def client_done(task):
            del self.clients[task]

        task.add_done_callback(client_done)
コード例 #3
0
    def _accept_client(self, client_reader, client_writer):
        """manage new client connections"""
        task = Task(self._handle_client(client_reader, client_writer))
        self.clients[task] = (client_reader, client_writer)

        def client_done(task):
            del self.clients[task]

        task.add_done_callback(client_done)
コード例 #4
0
    def reenter_after(self, target: Task, action: Callable):
        msg = self._message

        def act():
            action()
            return None

        cont = Continuation(act, msg)

        target.add_done_callback(lambda _: self.my_self.send_system_message(cont))
コード例 #5
0
    def cancel_test_on_exception(task: asyncio.Task):
        def maybe_cancel_clbk(t: asyncio.Task):
            exception = t.exception()
            if exception is None:
                return

            for task in asyncio.all_tasks():
                coro = task.get_coro()
                if coro.__qualname__ == request.function.__qualname__:
                    task.cancel()
                    return

        task.add_done_callback(maybe_cancel_clbk)
コード例 #6
0
ファイル: task_queue.py プロジェクト: torjc01/acapy-alice-bob
    def add_active(self,
                   task: asyncio.Task,
                   task_complete: Callable = None) -> asyncio.Task:
        """
        Register an active async task with an optional completion callback.

        Args:
            task: The asyncio task instance
            task_complete: An optional callback to run on completion
        """
        self.active_tasks.append(task)
        task.add_done_callback(
            lambda fut: self.completed_task(task, task_complete))
        return task
コード例 #7
0
ファイル: contract.py プロジェクト: pmgexpo17/ApiServicePeer
 def addFuture(self, future: Task, futRef: str):
   def onComplete(fut):
     try:
       self.pendingTasks.discard(fut)
       fut.result()
     except asyncio.CancelledError:
       logger.info(f"{self.id} {futRef} was cancelled")
     except Exception:
       kwArgs = {}
       if self.policy.logdetail == "VERBOSE":
         kwArgs["exc_info"] = True
       logger.error(f"{self.id} {futRef} errored", **kwArgs)
   future.add_done_callback(onComplete)
   self.pendingTasks.add(future)
コード例 #8
0
ファイル: sound_tracker.py プロジェクト: janbrrr/dndj
    def register_sound(self, group_index: int, sound_index: int,
                       task: asyncio.Task):
        """
        Register that the given task belongs to the given group_index and sound_index. Will automatically
        unregister the task after it has finished.

        Raises a `RuntimeError` if the task is already done. Finished tasks are not allowed to be registered.
        """
        logger.debug(
            f"Registering task for group={group_index}, sound={sound_index}")
        key = self._get_sound_key(group_index, sound_index)
        if task.done():
            raise RuntimeError(
                f"Task for group={group_index}, sound={sound_index} is done, but was registered!"
            )
        task.add_done_callback(
            functools.partial(self._unregister_sound, group_index,
                              sound_index))
        self.sound_to_task[key] = task
コード例 #9
0
ファイル: loop.py プロジェクト: pfreixes/qloop
    def _inherit_queue(self, coro):
        """Create a new task inheriting the partition
        assigned to the current task.

        If there is no current task, or the curren task
        does not have any queue will be assinged to the
        root one.

        Return a task object
        """
        task = Task(coro, loop=self)
        task.partition = _find_partition(self)
        if task._source_traceback:
            del task._source_traceback[-1]

        self._partitions[task.partition].add_task(task)
        task.add_done_callback(self._partitions[task.partition].remove_task,
                               task)
        return task
コード例 #10
0
    def add_active(
        self,
        task: asyncio.Task,
        task_complete: Callable = None,
        ident: str = None,
        timing: dict = None,
    ) -> asyncio.Task:
        """
        Register an active async task with an optional completion callback.

        Args:
            task: The asyncio task instance
            task_complete: An optional callback to run on completion
            ident: A string identifer for the task
            timing: An optional dictionary of timing information
        """
        self.active_tasks.append(task)
        task.add_done_callback(lambda fut: self.completed_task(
            task, task_complete, ident, timing))
        self.total_started += 1
        return task
コード例 #11
0
 def register_cancellable_task(self, task: asyncio.Task):
     self._cancellable_tasks.add(task)
     task.add_done_callback(lambda t: self._cancellable_tasks.discard(t))
     return task
コード例 #12
0
 def remember_task(self, task: asyncio.Task) -> None:
     """Remember a scheduled asyncio task, in case it needs to be
     cancelled
     """
     self.running_tasks.append(task)
     task.add_done_callback(self.forget_task)
コード例 #13
0
ファイル: worker_pool.py プロジェクト: aiokitchen/aiomisc
 def __task_add(self, task: asyncio.Task) -> None:
     self._statistic.task_added += 1
     task.add_done_callback(self.__task_store.remove)
     self.__task_store.add(task)
コード例 #14
0
ファイル: core.py プロジェクト: dls-controls/bluefly
 def task(self, task: Task):
     assert isinstance(task, Task), f"{task} is not a task"
     self._awaitable = task
     task.add_done_callback(self._run_callbacks)
コード例 #15
0
def wait_task_completed(task: asyncio.Task):
    if task.done() or task.cancelled():
        return
    signal = Event()
    task.add_done_callback(lambda x: signal.set())
    signal.wait()
コード例 #16
0
ファイル: pool.py プロジェクト: tzoiker/aiomisc
 def __task_add(self, task: asyncio.Task) -> None:
     task.add_done_callback(self.__task_store.remove)
     self.__task_store.add(task)