示例#1
0
文件: ecli_core.py 项目: klauer/ECLI
    def exit(self):
        """
        Called before the user exits IPython, notifying each registered
        plugin
        """
        logger.debug('Exiting')
        self.run_callback(self.CB_EXIT, self.__class__.__name__)

        for name, inst in self._extensions.iteritems():
            if inst is self:
                continue

            logger.debug('Plugin exit: %s' % name)
            try:
                inst.exit()
            except Exception as ex:
                print('Plugin %s exit failed: (%s) %s' %
                     (name, ex.__class__.__name__, ex))

                util.print_traceback(ex)

        # Detach the pyepics context or some background tasks might delay
        # exiting
        class CA_NoOperation(object):
            def ca_name(self, id):
                return ''

        epics.ca.detach_context()
        epics.ca.libca = CA_NoOperation()

        self._shell_exit()
示例#2
0
    def run_callback(self, name, handle_exceptions=True, show_traceback=None,
                     **kwargs):
        """
        Trigger a previously registered callback

        :param name: The callback name
        :param handle_exceptions: Catch exceptions and continue processing other
                                  callbacks
        :param show_traceback: A file-like object indicating where to print the
                               traceback to (or None to disable)
        :param kwargs: Keyword arguments to be passed to the callback functions
        """
        for fcn in self._cb_dict[name]:
            try:
                fcn(**kwargs)
            except Exception as ex:
                if handle_exceptions:
                    self.logger.debug('Callback %s failed' % (name, ),
                                      exc_info=True)
                    if show_traceback is not None:
                        print('Callback %s failed' % (name, ))
                        util.print_traceback(ex, f=show_traceback)

                else:
                    raise