Esempio n. 1
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
Esempio n. 2
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
        def _bootstrap_inner(self):
            print('in bootstrap')
            try:
                self._set_ident()
                self._set_tstate_lock()
                self._started.set()
                with threading._active_limbo_lock:
                    threading._active[self._ident] = self
                    del threading._limbo[self]

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

                try:
                    self.run()
                except SystemExit:
                    pass
                except:
                    # If sys.stderr is no more (most likely from interpreter
                    # shutdown) use self._stderr.  Otherwise still use sys (as in
                    # _sys) in case sys.stderr was redefined since the creation of
                    # self.
                    if threading._sys and threading._sys.stderr is not None:
                        print("Exception in thread %s:\n%s" %
                              (self.name, threading._format_exc()), file=threading._sys.stderr)
                    elif self._stderr is not None:
                        # Do the best job possible w/o a huge amt. of code to
                        # approximate a traceback (code ideas from
                        # Lib/traceback.py)
                        exc_type, exc_value, exc_tb = self._exc_info()
                        try:
                            print((
                                "Exception in thread " + self.name +
                                " (most likely raised during interpreter shutdown):"), file=self._stderr)
                            print((
                                "Traceback (most recent call last):"), file=self._stderr)
                            while exc_tb:
                                print((
                                    '  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)), file=self._stderr)
                                exc_tb = exc_tb.tb_next
                            print(("%s: %s" % (exc_type, exc_value)), file=self._stderr)
                        # Make sure that exc_tb gets deleted since it is a memory
                        # hog; deleting everything else is just for thoroughness
                        finally:
                            del exc_type, exc_value, exc_tb
                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.
                    #XXX self._exc_clear()
                    pass
            finally:
                self.close()  # ADDED CLOSE FUNCTION

                with threading._active_limbo_lock:
                    try:
                        # We don't call self._delete() because it also
                        # grabs _active_limbo_lock.
                        del threading._active[threading.get_ident()]
                    except:
                        pass