예제 #1
0
파일: greenlet.py 프로젝트: aathan/gevent
 def __handle_death_before_start(self, args):
     # args is (t, v, tb) or simply t or v.
     # The last two cases are transformed into (t, v, None);
     # if the single argument is an exception type, a new instance
     # is created; if the single argument is not an exception type and also
     # not an exception, it is wrapped in a BaseException (this is not
     # documented, but should result in better behaviour in the event of a
     # user error---instead of silently printing something to stderr, we still
     # kill the greenlet).
     if self._exc_info is None and self.dead:
         # the greenlet was never switched to before and it will
         # never be; _report_error was not called, the result was
         # not set, and the links weren't notified. Let's do it
         # here.
         #
         # checking that self.dead is true is essential, because
         # throw() does not necessarily kill the greenlet (if the
         # exception raised by throw() is caught somewhere inside
         # the greenlet).
         if len(args) == 1:
             arg = args[0]
             if isinstance(arg, type) and issubclass(arg, BaseException):
                 args = (arg, arg(), None)
             else:
                 args = (type(arg), arg, None)
         elif not args:
             args = (GreenletExit, GreenletExit(), None)
         if not issubclass(args[0], BaseException):
             # Random non-type, non-exception arguments.
             print("RANDOM CRAP", args)
             import traceback
             traceback.print_stack()
             args = (BaseException, BaseException(args), None)
         assert issubclass(args[0], BaseException)
         self.__report_error(args)
예제 #2
0
    def throw(self, *args):
        """Immediately switch into the greenlet and raise an exception in it.

        Should only be called from the HUB, otherwise the current greenlet is left unscheduled forever.
        To raise an exception in a safely manner from any greenlet, use :meth:`kill`.

        If a greenlet was started but never switched to yet, then also
        a) cancel the event that will start it
        b) fire the notifications as if an exception was raised in a greenlet

        """
        try:
            greenlet.throw(self, *args)
        finally:
            if self._exception is _NONE and self.dead:
                # the greenlet was never switched to before and it will never be, _report_error was not called
                # the result was not set and the links weren't notified. let's do it here.
                # checking that self.dead is true is essential, because throw() does not necessarily kill the greenlet
                # (if the exception raised by throw() is caught somewhere inside the greenlet).
                if len(args) == 1:
                    arg = args[0]
                    #if isinstance(arg, type):
                    if type(arg) is type(Exception):
                        args = (arg, arg(), None)
                    else:
                        args = (type(arg), arg, None)
                elif not args:
                    args = (GreenletExit, GreenletExit(), None)
                self._report_error(args)
예제 #3
0
 def __handle_death_before_start(self, args):
     # args is (t, v, tb) or simply t or v
     if self._exc_info is None and self.dead:
         # the greenlet was never switched to before and it will never be, _report_error was not called
         # the result was not set and the links weren't notified. let's do it here.
         # checking that self.dead is true is essential, because throw() does not necessarily kill the greenlet
         # (if the exception raised by throw() is caught somewhere inside the greenlet).
         if len(args) == 1:
             arg = args[0]
             #if isinstance(arg, type):
             if type(arg) is type(Exception):
                 args = (arg, arg(), None)
             else:
                 args = (type(arg), arg, None)
         elif not args:
             args = (GreenletExit, GreenletExit(), None)
         self._report_error(args)
예제 #4
0
 def __handle_death_before_start(self, args):
     # args is (t, v, tb) or simply t or v
     if self._exc_info is None and self.dead:
         # the greenlet was never switched to before and it will
         # never be; _report_error was not called, the result was
         # not set, and the links weren't notified. Let's do it
         # here.
         #
         # checking that self.dead is true is essential, because
         # throw() does not necessarily kill the greenlet (if the
         # exception raised by throw() is caught somewhere inside
         # the greenlet).
         if len(args) == 1:
             arg = args[0]
             if issubclass(arg, BaseException):
                 args = (arg, arg(), None)
             else:
                 args = (type(arg), arg, None)
         elif not args:
             args = (GreenletExit, GreenletExit(), None)
         assert issubclass(args[0], BaseException)
         self.__report_error(args)
예제 #5
0
 def terminating_target():
     raise GreenletExit()
예제 #6
0
 def __init__(self, destroy_loop):
     GreenletExit.__init__(self, destroy_loop)
     self.destroy_loop = destroy_loop
예제 #7
0
 def fmain(*args):
     raise GreenletExit(*args)