Ejemplo n.º 1
0
def shutdown(exitstatus):
    # In GUI mode, this is called after the GUI exits.

    # Restore the default exception handler, in case something goes
    # wrong during shutdown, and the machinery to display OOF
    # exceptions has already been dismantled.  This call must come
    # before mainthread_delete().
    excepthook.assign_excepthook()

    # On some systems (at least OS X 10.5.7) it's important to delete
    # the main thread's ThreadState object explicitly before calling
    # sys.exit().  If called implicitly by sys.exit, the ThreadState
    # destructor crashes.  This must come after the GUI has been
    # stopped, or else subthreads used in stopping the GUI will fail.
    threadstate.mainthread_delete()

    ## gc.garbage is a list of objects which couldn't be deleted,
    ## because they have circular references *and* __del__ methods.
    ## Python can't use garbage collection on such objects because it
    ## doesn't know the order in which to call the __del__ methods.
    if gc.garbage:
        debug.fmsg("garbage=", gc.garbage)
        # for g in gc.garbage:
        #     from ooflib.SWIG.common import doublevec
        #     if isinstance(g, doublevec.DoubleVecPtr):
        #         debug.dumpReferrers(g, levels=2)

    sys.stdout.flush()
    sys.exit(exitstatus)
Ejemplo n.º 2
0
 def run(self):
     if self.error is None:
         self.lines = self.fileobj.readlines()
         nlines = len(self.lines)
         nblocks = len(self.blocks)
         self.blocks.append(nlines + 1)  # avoid special case for last block
         self.excepthook = excepthook.assign_excepthook(
             _ScriptExceptHook(self))
         # We can't use a try/finally here to restore an old excepthook
         # after we're done reading the file.  If an exception is
         # raised, the "finally" clause would run before the
         # excepthook.
         for blockno in range(nblocks):
             # line numbers start at 1, not 0
             blockstart = self.blocks[blockno] - 1
             blockend = self.blocks[blockno + 1] - 1
             source = ''.join(self.lines[blockstart:blockend])
             more = self.runsource(
                 source, encodeLocation(self.filename, blockstart))
             if more:
                 raise ooferror.ErrPyProgrammingError(
                     "Error reading script!")
             self.progress(blockend + 1, nlines)
             if self.stop() or self.error:
                 break
         excepthook.remove_excepthook(self.excepthook)
     self.done()
Ejemplo n.º 3
0
def shutdown(exitstatus):
    # Restore the default exception handler, in case something goes
    # wrong during shutdown, and the machinery to display OOF
    # exceptions has already been dismantled.  This call must come
    # before mainthread_delete().
    excepthook.assign_excepthook()

    # On some systems (at least OS X 10.5.7) it's important to delete
    # the main thread's ThreadState object explicitly before calling
    # sys.exit().  If called implicitly by sys.exit, the ThreadState
    # destructor crashes.  This must come after the GUI has been
    # stopped, or else subthreads used in stopping the GUI will fail.
    threadstate.mainthread_delete()

    ## gc.garbage is a list of objects which couldn't be deleted,
    ## because they have circular references *and* __del__ methods.
    ## Python can't use garbage collection on such objects because it
    ## doesn't know the order in which to call the __del__ methods.
    if gc.garbage:
        debug.fmsg("garbage=", gc.garbage)

    sys.stdout.flush()
    sys.exit(exitstatus)
Ejemplo n.º 4
0
 def run(self):
     miniThreadManager.add(self)
     try:
         try:
             self.threadstate = threadstate.ThreadState()
             #                 debug.fmsg("assigning excepthook, function=", self.function)
             hook = excepthook.assign_excepthook(excepthook.OOFexceptHook())
             self.function(*self.args, **self.kwargs)
             excepthook.remove_excepthook(hook)
         except StopThread:
             excepthook.remove_excepthook(hook)
             return
         # TODO SWIG1.3: After conversion to SWIG 1.3, OOF
         # exceptions will probably be subclasses of Exception.
         except (Exception, ooferror.ErrErrorPtr), exception:
             from ooflib.common.IO import reporter
             reporter.error(exception)
             sys.excepthook(*sys.exc_info())
     finally:
         miniThreadManager.remove(self)
         self.threadstate = None
Ejemplo n.º 5
0
    def run(self):
        miniThreadManager.add(self)
        try:
            try:
                self.threadstate = threadstate.ThreadState()
#                 debug.fmsg("assigning excepthook, function=", self.function)
                hook = excepthook.assign_excepthook(excepthook.OOFexceptHook())
                self.function(*self.args, **self.kwargs)
                excepthook.remove_excepthook(hook)
            except StopThread:
                excepthook.remove_excepthook(hook)
                return
            # TODO SWIG1.3: After conversion to SWIG 1.3, OOF
            # exceptions will probably be subclasses of Exception.
            except (Exception, ooferror.ErrErrorPtr), exception:
                from ooflib.common.IO import reporter
                reporter.error(exception)
                sys.excepthook(*sys.exc_info())
        finally:
            miniThreadManager.remove(self)
            self.threadstate = None
Ejemplo n.º 6
0
 def run(self):
     miniThreadManager.add(self)
     try:
         try:
             self.threadstate = threadstate.OOFThreadState()
             hook = excepthook.assign_excepthook(excepthook.OOFexceptHook())
             # debug.fmsg("Starting thread %s: %s" %
             #            (self.id(), self.function))
             self.function(*self.args, **self.kwargs)
             # debug.fmsg("Finished thread", self.id())
             excepthook.remove_excepthook(hook)
         except StopThread:
             excepthook.remove_excepthook(hook)
             return
         # TODO 3.1: After conversion to SWIG 2.x, if that ever
         # happens, OOF exceptions will probably be subclasses of
         # Exception.
         except (Exception, ooferror.ErrErrorPtr), exception:
             from ooflib.common.IO import reporter
             reporter.error(exception)
             sys.excepthook(*sys.exc_info())
     finally:
         miniThreadManager.remove(self)
         self.threadstate = None
Ejemplo n.º 7
0
 def run(self):
     if self.error is None:
         self.lines = self.fileobj.readlines()
         nlines = len(self.lines)
         nblocks = len(self.blocks)
         self.blocks.append(nlines + 1)  # avoid special case for last block
         self.excepthook = excepthook.assign_excepthook(_ScriptExceptHook(self))
         # We can't use a try/finally here to restore an old excepthook
         # after we're done reading the file.  If an exception is
         # raised, the "finally" clause would run before the
         # excepthook.
         for blockno in range(nblocks):
             # line numbers start at 1, not 0
             blockstart = self.blocks[blockno] - 1
             blockend = self.blocks[blockno + 1] - 1
             source = "".join(self.lines[blockstart:blockend])
             more = self.runsource(source, encodeLocation(self.filename, blockstart))
             if more:
                 raise ooferror.ErrPyProgrammingError("Error reading script!")
             self.progress(blockend + 1, nlines)
             if self.stop() or self.error:
                 break
         excepthook.remove_excepthook(self.excepthook)
     self.done()
Ejemplo n.º 8
0
 def initialize(self):  # called on subthread
     #         debug.fmsg("assigning excepthook, menuitem=", self.menuitem.path())
     self.excepthook = excepthook.assign_excepthook(
         excepthook.OOFexceptHook())
Ejemplo n.º 9
0
    def initialize(self):       # called on subthread
#         debug.fmsg("assigning excepthook, menuitem=", self.menuitem.path())
        self.excepthook = excepthook.assign_excepthook(
            excepthook.OOFexceptHook())