def _thread_bootstrap_2_7(self):
    """This is a replacement "method" for the Thread class in Python 2.7,
    designed to let an exception fall through to the debugger."""

    # noinspection PyProtectedMember
    # noinspection PyUnresolvedReferences
    # noinspection PyProtectedMember
    # noinspection PyUnresolvedReferences
    from threading import (
        _active,
        _active_limbo_lock,
        _get_ident,
        _limbo,
        _profile_hook,
        _sys,
        _trace_hook,
    )

    try:
        self._set_ident()
        self._Thread__started.set()
        with _active_limbo_lock:
            _active[self._Thread__ident] = self
            del _limbo[self]
        if __debug__:
            self._note("%s.__bootstrap(): thread started", self)

        # if _trace_hook:
        #     self._note("%s.__bootstrap(): registering trace hook", self)
        #     _sys.settrace(_trace_hook)
        if _profile_hook:
            self._note("%s.__bootstrap(): registering profile hook", self)
            _sys.setprofile(_profile_hook)

        try:
            self.run()
        except SystemExit:
            if __debug__:
                self._note("%s.__bootstrap(): raised SystemExit", self)
        else:
            if __debug__:
                self._note("%s.__bootstrap(): normal return", self)
        finally:
            # Prevent a race in
            # test_threading.test_no_refcycle_through_target when
            # the exception keeps the target alive past when we
            # assert that it's dead.
            self._Thread__exc_clear()
    finally:
        with _active_limbo_lock:
            self._Thread__stop()
            try:
                # We don't call self.__delete() because it also
                # grabs _active_limbo_lock.
                del _active[_get_ident()]
            except:
                pass
Exemple #2
0
def _bootstrap_inner(self):
    try:
        self._set_ident()
        self._Thread__started.set()
        with _active_limbo_lock:
            _active[self._Thread__ident] = self
            del _limbo[self]

        if _trace_hook:
            _sys.settrace(_trace_hook)
        if _profile_hook:
            _sys.setprofile(_profile_hook)

        try:
            self.run()
        except SystemExit:
            pass
        except:
            if _sys:
                _sys.stderr.write("Exception in thread %s:\n%s\n" %
                                    (self.name, _format_exc()))
            else:
                exc_type, exc_value, exc_tb = self._exc_info()
                try:
                    self._stderr.write(
                        (
                        "Exception in thread " + self.name +
                        " (most likely raised during interpreter shutdown):")
                        )

                    self._stderr.write("Traceback (most recent call last):")
                    while exc_tb:
                        self._stderr.write(
                            '  File "%s", line %s, in %s' %
                            (exc_tb.tb_frame.f_code.co_filename,
                                exc_tb.tb_lineno,
                                exc_tb.tb_frame.f_code.co_name))

                        exc_tb = exc_tb.tb_next
                    self._stderr.write("%s: %s" % (exc_type, exc_value))
                finally:
                    del exc_type, exc_value, exc_tb
        finally:
            pass
    finally:
        with _active_limbo_lock:
            self._Thread__stop()
            try:
                del _active[self._Thread__ident]
            except:
                pass
def _thread_bootstrap_2_7(self):
    """This is a replacement "method" for the Thread class in Python 2.7,
    designed to let an exception fall through to the debugger."""

    # noinspection PyProtectedMember
    # noinspection PyUnresolvedReferences
    from threading import _active_limbo_lock, _active, _limbo, _trace_hook

    # noinspection PyProtectedMember
    # noinspection PyUnresolvedReferences
    from threading import _profile_hook, _sys, _get_ident

    try:
        self._set_ident()
        self._Thread__started.set()
        with _active_limbo_lock:
            _active[self._Thread__ident] = self
            del _limbo[self]
        if __debug__:
            self._note("%s.__bootstrap(): thread started", self)

        # if _trace_hook:
        #     self._note("%s.__bootstrap(): registering trace hook", self)
        #     _sys.settrace(_trace_hook)
        if _profile_hook:
            self._note("%s.__bootstrap(): registering profile hook", self)
            _sys.setprofile(_profile_hook)

        try:
            self.run()
        except SystemExit:
            if __debug__:
                self._note("%s.__bootstrap(): raised SystemExit", self)
        else:
            if __debug__:
                self._note("%s.__bootstrap(): normal return", self)
        finally:
            # Prevent a race in
            # test_threading.test_no_refcycle_through_target when
            # the exception keeps the target alive past when we
            # assert that it's dead.
            self._Thread__exc_clear()
    finally:
        with _active_limbo_lock:
            self._Thread__stop()
            try:
                # We don't call self.__delete() because it also
                # grabs _active_limbo_lock.
                del _active[_get_ident()]
            except:
                pass
Exemple #4
0
        def _bootstrap_inner(self):  # NOQA
            try:
                self._set_ident()
                self._started.set()
                with _active_limbo_lock:
                    _active[self._ident] = self
                    del _limbo[self]

                if _trace_hook:
                    _sys.settrace(_trace_hook)
                if _profile_hook:
                    _sys.setprofile(_profile_hook)

                try:
                    self.run()
                except SystemExit:
                    pass
                except:
                    if _sys:
                        _sys.stderr.write("Exception in thread %s:\n%s\n" %
                                          (self.name, _format_exc()))
                    else:
                        exc_type, exc_value, exc_tb = self._exc_info()
                        try:
                            self._stderr.write(
                                "Exception in thread " + self.name + " (most "
                                "likely raised during interpreter shutdown):")

                            self._stderr.write("Traceback (most recent call "
                                               "last):")
                            while exc_tb:
                                self._stderr.write(
                                    '  File "%s", line %s, in %s' %
                                    (exc_tb.tb_frame.f_code.co_filename,
                                     exc_tb.tb_lineno,
                                     exc_tb.tb_frame.f_code.co_name))

                                exc_tb = exc_tb.tb_next
                            self._stderr.write("%s: %s" %
                                               (exc_type, exc_value))
                        finally:
                            del exc_type, exc_value, exc_tb
                finally:
                    pass
            finally:
                with _active_limbo_lock:
                    self._stop()
                    try:
                        del _active[self._ident]
                    except:
                        pass