def dumpTrace(start=0, end=-1): ## Use start=-3, end=-2 if you only want to see the calling ## function of the function that calls dumpTrace. lock.acquire() try: stack = traceback.extract_stack() depth = len(stack) thread = threadstate.findThreadNumber() if parallel_enable.enabled(): from ooflib.SWIG.common import mpitools rank = "%02d" % mpitools.Rank() else: rank = '--' lines = [ '+++-%04d-%02d-%s--------- debug.dumpTrace --------------' % (depth, thread, rank) ] for line in stack[start:end]: lines.append('+++%30s:%3d\t%s\t\t%s' % (line[0], line[1], line[2], line[3])) lines.append('+++-------------- end trace -----------------') print >> sys.stderr, string.join(lines, '\n') finally: lock.release()
def __init__(self, func, args=(), kwargs={}): self.func = func self.args = args self.kwargs = kwargs self.event = threading.Event() self.result = None self.callingthread = threadstate.findThreadNumber()
def remove_excepthook(hook): _exceptLock.acquire() threadno = threadstate.findThreadNumber() # hookstack = _exceptStacks[threadno] # # debug.fmsg("stack=", [id(h) for h in hookstack], "hook=", id(hook)) # assert hookstack[-1] is hook # oldhook = hookstack.pop() # if not hookstack: # del _exceptStacks[threadno] ## The preceding block of code used to be much more cautious, but the ## caution was inserted when debugging a problem that turned out to be ## elsewhere. Here's the cautious version, in case returning to the ## incautious version was a mistake: oldhook = None if threadno in _exceptStacks: hookstack = _exceptStacks[threadno] if hook in hookstack: oldhook = hookstack.pop() while oldhook is not hook: oldhook = hookstack.pop() if not hookstack: del _exceptStacks[threadno] _exceptLock.release() return oldhook
def fmsg(*args): from ooflib.SWIG.common import ooferror if _debug_mode: lock.acquire() try: stack = traceback.extract_stack() depth = len(stack) filename = string.split(stack[-2][0], '/')[-1] func = stack[-2][2] line = stack[-2][1] try: thread = "%02d"% threadstate.findThreadNumber() except: thread = '??' if parallel_enable.enabled(): from ooflib.SWIG.common import mpitools rank="%02d" % mpitools.Rank() else: rank='--' print >> sys.stderr, \ ('-%04d-%s-%s'%(depth,thread,rank))+'-'*(depth-1), \ '%s(%d):%s'%(filename, line, func),\ string.join(map(str, args), ' ') finally: # pass lock.release()
def fmsg(*args): ## Importing ooferror here hangs the program when a binary data ## file is loaded if fmsg is used in OOFIdleCallback. WTF? There ## may be no real need to import ooferror here, but it was ## imported here once, and mysteriously caused a problem. ## (There's a comment in mainthreadGUI that refers to this ## comment.) # from ooflib.SWIG.common import ooferror if _debug_mode: lock.acquire() try: stack = traceback.extract_stack() depth = len(stack) filename = string.split(stack[-2][0], '/')[-1] func = stack[-2][2] line = stack[-2][1] try: thread = "%02d"% threadstate.findThreadNumber() except: thread = '??' if parallel_enable.enabled(): from ooflib.SWIG.common import mpitools rank="%02d" % mpitools.Rank() else: rank='--' print >> sys.stderr, \ ('-%04d-%s-%s'%(depth,thread,rank))+'-'*(depth-1), \ '%s(%d):%s'%(filename, line, func),\ string.join(map(str, args), ' ') finally: lock.release()
def loadscript(menuitem, filename): if filename is not None: debug.fmsg('reading', filename, 'in thread', threadstate.findThreadNumber()) kwargs = {} if subScriptErrorHandler: kwargs['errhandler'] = subScriptErrorHandler interp = PScriptLoader(filename, **kwargs) interp.run() if interp.error: # If the interpreter raised an exception and we're in # batch mode, the shell error status won't be set unless a # new exception is raised here. The old exception has # already been handled by the time we get to this point. # interp.error[0] is the class of the exception. # interp.error[1] is its value. errorname = interp.error[0].__name__ if errorname.lower()[0] in "aeiou": article = "an" else: article = "a" raise ooferror.ErrUserError( "Script '%s' raised %s %s exception" % (filename, article, interp.error[0].__name__) # "Script '%s' raised %s %s exception: %s" % # (filename, article, interp.error[0].__name__, interp.error[1]) ) debug.fmsg('finished reading', filename)
def fmsg(*args): ## Importing ooferror here hangs the program when a binary data ## file is loaded if fmsg is used in OOFIdleCallback. WTF? There ## may be no real need to import ooferror here, but it was ## imported here once, and mysteriously caused a problem. ## (There's a comment in mainthreadGUI that refers to this ## comment.) # from ooflib.SWIG.common import ooferror if _debug_mode: lock.acquire() try: stack = traceback.extract_stack() depth = len(stack) filename = string.split(stack[-2][0], '/')[-1] func = stack[-2][2] line = stack[-2][1] try: thread = "%02d" % threadstate.findThreadNumber() except: thread = '??' if parallel_enable.enabled(): from ooflib.SWIG.common import mpitools rank = "%02d" % mpitools.Rank() else: rank = '--' print >> sys.stderr, \ ('-%04d-%s-%s'%(depth,thread,rank))+'-'*(depth-1), \ '%s(%d):%s'%(filename, line, func),\ string.join(map(str, args), ' ') finally: lock.release()
def get_excepthook(): threadno = threadstate.findThreadNumber() if threadno not in _exceptStacks: return sys.__excepthook__ hookstack = _exceptStacks[threadno] if hookstack: return hookstack[-1] return None
def undisplay_bar(self): if sys.stdout.isatty(): self.outlock.acquire() try: threadno = threadstate.findThreadNumber() if threadno in self.thread_bars: del self.thread_bars[threadno] finally: self.outlock.release() self.display_bar()
def undisplay_bar(self): if sys.stdout.isatty(): MessageManager.outlock.acquire() try: threadno = threadstate.findThreadNumber() if threadno in self.thread_bars: del self.thread_bars[threadno] finally: MessageManager.outlock.release() self.display_bar()
def assign_excepthook(newhook=sys.__excepthook__): # debug.fmsg("adding hook", id(newhook)) _exceptLock.acquire() threadno = threadstate.findThreadNumber() try: hookstack = _exceptStacks[threadno] except KeyError: hookstack = _exceptStacks[threadno] = [] hookstack.append(newhook) _exceptLock.release() return newhook
def callerID(depth=-3): if _debug_mode: lock.acquire() try: stack = traceback.extract_stack() thread = threadstate.findThreadNumber() if parallel_enable.enabled(): from ooflib.SWIG.common import mpitools rank = "%02d" % mpitools.Rank() else: rank = "" line = stack[depth] return '+++%02d++%s+++%30s:%3d\t%s\t\t%s' % \ (thread, rank, line[0], line[1], line[2], line[3]) finally: lock.release()
def msg(*args): if _debug_mode: lock.acquire() try: stack = traceback.extract_stack() depth = len(stack) thread = threadstate.findThreadNumber() if parallel_enable.enabled(): from ooflib.SWIG.common import mpitools rank = "%02d" % mpitools.Rank() else: rank = '--' print >> sys.stderr, \ ('-%04d-%02d-%s'%(depth,thread,rank))+'-'*(depth-1), \ string.join(map(str, args), ' ') finally: lock.release()
def msg(*args): if _debug_mode: lock.acquire() try: stack = traceback.extract_stack() depth = len(stack) thread = threadstate.findThreadNumber() if parallel_enable.enabled(): from ooflib.SWIG.common import mpitools rank="%02d" % mpitools.Rank() else: rank='--' print >> sys.stderr, \ ('-%04d-%02d-%s'%(depth,thread,rank))+'-'*(depth-1), \ string.join(map(str, args), ' ') finally: lock.release()
def __init__(self, alpha, gamma, iterations): self.alpha = alpha self.gamma = gamma self.iterations = iterations self.count = 0 self.solver_converged = True self.meshname = None threadno = threadstate.findThreadNumber() ## create material materialmanager.materialmanager.add_secret(self.materialName) ## SkeletonRelaxationRateTensor is the PropertyRegistration for the ## SkeletonRelaxationRate property. relaxPropReg = skeletonrelaxationrate.SkeletonRelaxationRateTensor.\ named_copy("__relaxationrate%d__" % threadno, secret=True) relaxPropReg.getParameter("gamma").value = self.gamma relaxPropReg.getParameter("alpha").value = self.alpha self.skelRelRate = relaxPropReg() # gamma_parameter = \ # skeletonrelaxationrate.SkeletonRelaxationRateTensor.getParameter( # 'gamma') # gamma_parameter.value = self.gamma # alpha_parameter = \ # skeletonrelaxationrate.SkeletonRelaxationRateTensor.getParameter( # 'alpha') # alpha_parameter.value = self.alpha # self.skelRelRate = skeletonrelaxationrate.SkeletonRelaxationRateTensor() materialmanager.materialmanager.add_prop(self.materialName, self.skelRelRate.name()) # isotropic elasticity stiffnessPropReg = iso.IsotropicElasticity.named_copy( "__stiffness%d__" % threadno, secret=True) stiffnessPropReg.getParameter('cijkl').value = \ isocijkl.IsotropicRank4TensorCij(c11=1.0, c12=0.5) self.stiffness = stiffnessPropReg() materialmanager.materialmanager.add_prop( self.materialName, self.stiffness.name())
def display_bar(self, newbars=None): if sys.stdout.isatty(): # Don't try to write progressbars to a file! MessageManager.outlock.acquire() try: if newbars: # Use '|' to separate progress bars from the same thread txt = " | ".join(filter(None, newbars)) self.thread_bars[threadstate.findThreadNumber()] = txt # Erase old bar display oldlen = len(self.bar_text) if oldlen: # overwrite old bar sys.stdout.write('\r' + oldlen * ' ' + '\r') # Redisplay all bars from all threads. Use '||' to # separate progress bars from different threads. self.bar_text = ' || '.join( txt for txt in self.thread_bars.values() if txt) sys.stdout.write(self.bar_text) sys.stdout.flush() finally: MessageManager.outlock.release()
def dumpTrace(start=0, end=-1): ## Use start=-3, end=-2 if you only want to see the calling ## function of the function that calls dumpTrace. lock.acquire() try: stack = traceback.extract_stack() depth = len(stack) thread = threadstate.findThreadNumber() if parallel_enable.enabled(): from ooflib.SWIG.common import mpitools rank="%02d" % mpitools.Rank() else: rank='--' lines = ['+++-%04d-%02d-%s--------- debug.dumpTrace --------------' % (depth, thread, rank) ] for line in stack[start:end]: lines.append('+++%30s:%3d\t%s\t\t%s' % (line[0],line[1], line[2],line[3])) lines.append('+++-------------- end trace -----------------') print >> sys.stderr, string.join(lines, '\n') finally: lock.release()
def display_bar(self, newbars=None): if sys.stdout.isatty(): # Don't try to write progressbars to a file! MessageManager.outlock.acquire() try: if newbars: # Use '|' to separate progress bars from the same thread txt = " | ".join(filter(None, newbars)) self.thread_bars[threadstate.findThreadNumber()] = txt # Erase old bar display oldlen = len(self.bar_text) if oldlen: # overwrite old bar sys.stdout.write('\r' + oldlen*' ' + '\r') # Redisplay all bars from all threads. Use '||' to # separate progress bars from different threads. self.bar_text = ' || '.join(txt for txt in self.thread_bars.values() if txt) sys.stdout.write(self.bar_text) sys.stdout.flush() finally: MessageManager.outlock.release()
def exceptHookDepth(): threadno = threadstate.findThreadNumber() if threadno not in _exceptStacks: return 0 return len(_exceptStacks[threadno])