Exemple #1
0
 def _cancel_wait(self, watcher, error):
     if watcher.active:
         switch = watcher.callback
         if switch is not None:
             greenlet = getattr(switch, '__self__', None)
             if greenlet is not None:
                 greenlet.throw(error)
Exemple #2
0
 def _cancel_wait(self, watcher, error):
     if watcher.active:
         switch = watcher.callback
         if switch is not None:
             greenlet = getattr(switch, '__self__', None)
             if greenlet is not None:
                 greenlet.throw(error)
def cancel_all_greenlets():
    for greenlet in greenlet_list[:]: # use copy since this loop will modify the contents
        if greenlet:
            try:
                greenlet.throw(KeyboardInterrupt)
            except KeyboardInterrupt:
                pass

        greenlet_list.remove(greenlet)
Exemple #4
0
    def _(*args, **kwargs):
        greenlet = GreenletWorker(callable)
        # switch to the new greenlet
        result = greenlet.switch(*args, **kwargs)
        # back to the parent
        while is_async(result):
            # keep on switching back to the greenlet if we get a Future
            try:
                result = greenlet.switch((yield from result))
            except Exception as exc:
                result = greenlet.throw(exc)

        return greenlet.switch(result)
Exemple #5
0
    def _(*args, **kwargs):
        greenlet = GreenletWorker(callable)
        # switch to the new greenlet
        result = greenlet.switch(*args, **kwargs)
        # back to the parent
        while is_async(result):
            # keep on switching back to the greenlet if we get a Future
            try:
                result = greenlet.switch((yield from result))
            except Exception as exc:
                result = greenlet.throw(exc)

        return greenlet.switch(result)
Exemple #6
0
    def _green_task(self, greenlet, task):
        # Run in the main greenlet of the event-loop thread

        while task is not _DONE:
            # switch to the greenlet to start the task
            task = greenlet.switch(task)

            # if an asynchronous result is returned, yield from
            while is_async(task):
                try:
                    task = yield from task
                except Exception as exc:
                    # This call can return an asynchronous component
                    task = greenlet.throw(exc)
Exemple #7
0
    def _green_task(self, greenlet, task):
        # Run in the main greenlet of the event-loop thread

        while task is not _DONE:
            # switch to the greenlet to start the task
            task = greenlet.switch(task)

            # if an asynchronous result is returned, yield from
            while is_async(task):
                try:
                    task = yield from task
                except Exception as exc:
                    # This call can return an asynchronous component
                    task = greenlet.throw(exc)