Python traceback 模块,print_last() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用traceback.print_last()

项目:yt    作者:yt-project    | 项目源码 | 文件源码
def parallel_root_only(func):
    """
    This decorator blocks and calls the function on the root processor,
    but does not broadcast results to the other processors.
    """
    @wraps(func)
    def root_only(*args, **kwargs):
        if not parallel_capable:
            return func(*args, **kwargs)
        comm = _get_comm(args)
        rv = None
        if comm.rank == 0:
            try:
                rv = func(*args, **kwargs)
                all_clear = 1
            except Exception:
                traceback.print_last()
                all_clear = 0
        else:
            all_clear = None
        all_clear = comm.mpi_bcast(all_clear)
        if not all_clear: raise RuntimeError
        return rv
    return root_only
项目:specto    作者:mrknow    | 项目源码 | 文件源码
def __clear_break(self, pid, address):
        """
        Used by L{dont_break_at} and L{dont_stalk_at}.

        @type  pid: int
        @param pid: Process global ID.

        @type  address: int or str
        @param address:
            Memory address of code instruction to break at. It can be an
            integer value for the actual address or a string with a label
            to be resolved.
        """
        if type(address) not in (int, long):
            unknown = True
            label = address
            try:
                deferred = self.__deferredBP[pid]
                del deferred[label]
                unknown = False
            except KeyError:
##                traceback.print_last()      # XXX DEBUG
                pass
            aProcess = self.system.get_process(pid)
            try:
                address = aProcess.resolve_label(label)
                if not address:
                    raise Exception()
            except Exception:
##                traceback.print_last()      # XXX DEBUG
                if unknown:
                    msg = ("Can't clear unknown code breakpoint"
                           " at %s in process ID %d")
                    msg = msg % (label, pid)
                    warnings.warn(msg, BreakpointWarning)
                return
        if self.has_code_breakpoint(pid, address):
            self.erase_code_breakpoint(pid, address)
项目:OpenXMolar    作者:debasishm89    | 项目源码 | 文件源码
def __clear_break(self, pid, address):
        """
        Used by L{dont_break_at} and L{dont_stalk_at}.

        @type  pid: int
        @param pid: Process global ID.

        @type  address: int or str
        @param address:
            Memory address of code instruction to break at. It can be an
            integer value for the actual address or a string with a label
            to be resolved.
        """
        if type(address) not in (int, long):
            unknown = True
            label = address
            try:
                deferred = self.__deferredBP[pid]
                del deferred[label]
                unknown = False
            except KeyError:
##                traceback.print_last()      # XXX DEBUG
                pass
            aProcess = self.system.get_process(pid)
            try:
                address = aProcess.resolve_label(label)
                if not address:
                    raise Exception()
            except Exception:
##                traceback.print_last()      # XXX DEBUG
                if unknown:
                    msg = ("Can't clear unknown code breakpoint"
                           " at %s in process ID %d")
                    msg = msg % (label, pid)
                    warnings.warn(msg, BreakpointWarning)
                return
        if self.has_code_breakpoint(pid, address):
            self.erase_code_breakpoint(pid, address)
项目:core    作者:getavalon    | 项目源码 | 文件源码
def show(root=None, debug=False, parent=None):
    """Display Loader GUI

    Arguments:
        debug (bool, optional): Run loader in debug-mode,
            defaults to False

    """

    # Remember window
    if module.window is not None:
        try:
            return module.window.show()
        except RuntimeError as e:
            if not e.message.rstrip().endswith("already deleted."):
                raise

            # Garbage collected
            module.window = None

    if debug:
        import traceback
        sys.excepthook = lambda typ, val, tb: traceback.print_last()

        io.install()

        any_project = next(
            project for project in io.projects()
            if project.get("active", True) is not False
        )

        api.Session["AVALON_PROJECT"] = any_project["name"]

    with lib.application():
        window = Window(parent)
        window.show()

        window.refresh()

        module.window = window
项目:core    作者:getavalon    | 项目源码 | 文件源码
def show(debug=False, parent=None):
    """Display asset creator GUI

    Arguments:
        creator (func, optional): Callable function, passed `name`,
            `family` and `use_selection`, defaults to `creator`
            defined in :mod:`pipeline`
        debug (bool, optional): Run loader in debug-mode,
            defaults to False

    """

    if module.window:
        module.window.close()
        del(module.window)

    if debug:
        from avalon import mock
        for creator in mock.creators:
            api.register_plugin(api.Creator, creator)

        import traceback
        sys.excepthook = lambda typ, val, tb: traceback.print_last()

        io.install()

        any_project = next(
            project for project in io.projects()
            if project.get("active", True) is not False
        )

        api.Session["AVALON_PROJECT"] = any_project["name"]
        module.project = any_project["name"]

    with lib.application():
        window = Window(parent)
        window.refresh()
        window.show()

        module.window = window
项目:oacids    作者:openaps    | 项目源码 | 文件源码
def run (self, manager, Q):
    print "running", self, self.running
    while self.running or not Q.empty( ):
      item, callbacks = Q.get( )
      on_ack, on_error = callbacks
      print "GOT FROM Q", item
      results = None
      # print "ALL SCHEDULED", manager.master.scheduler.schedules
      trigger = get_trigger_for(item.get('trigger', None), manager.master.scheduler)
      print "FROM TRIGGER", trigger
      # http://stackoverflow.com/questions/5943249/python-argparse-and-controlling-overriding-the-exit-status-code
      fuzz = dbus.Dictionary(item, signature="sv")
      # fuzz.update(**item)
      manager.Phase('get', fuzz);
      update_phase(trigger, 'Running')
      try:
        app = DoTool.Make(item)
        manager.Phase('make', fuzz);
        print "GOT ITEM", item, app
        results = app( )
        update_phase(trigger, 'Success')
        manager.Phase('success', fuzz);
        on_ack(results)
        # bad
        time.sleep(0.150)

      except (Exception, SystemExit), e:
        print "EXCEPTINO!!!!"
        print e
        manager.Phase('error', fuzz);
        update_phase(trigger, 'Error')
        time.sleep(0.150)
        on_error( )
        if e:
          traceback.print_exc(file=sys.stdout)
          # traceback.print_last( )
      finally:

        # update_phase(trigger, 'Done')
        # update_phase(trigger, 'Finish')
        update_phase(trigger, 'Remove')
        print "DONE", results
        Q.task_done( )
项目:core    作者:getavalon    | 项目源码 | 文件源码
def show(root=None, debug=False, parent=None, use_context=False):
    """Display Loader GUI

    Arguments:
        debug (bool, optional): Run loader in debug-mode,
            defaults to False
        parent (QtCore.QObject, optional): The Qt object to parent to.
        use_context (bool): Whether to apply the current context upon launch

    """

    # Remember window
    if module.window is not None:
        try:
            module.window.show()

            # If the window is minimized then unminimize it.
            if module.window.windowState() & QtCore.Qt.WindowMinimized:
                module.window.setWindowState(QtCore.Qt.WindowActive)

            # Raise and activate the window
            module.window.raise_()             # for MacOS
            module.window.activateWindow()     # for Windows
            module.window.refresh()
            return
        except RuntimeError as e:
            if not e.message.rstrip().endswith("already deleted."):
                raise

            # Garbage collected
            module.window = None

    if debug:
        import traceback
        sys.excepthook = lambda typ, val, tb: traceback.print_last()

        io.install()

        any_project = next(
            project for project in io.projects()
            if project.get("active", True) is not False
        )

        api.Session["AVALON_PROJECT"] = any_project["name"]
        module.project = any_project["name"]

    with lib.application():
        window = Window(parent)
        window.show()

        if use_context:
            context = {"asset": api.Session['AVALON_ASSET'],
                       "silo": api.Session['AVALON_SILO']}
            window.set_context(context, refresh=True)
        else:
            window.refresh()

        module.window = window