def dumpState(self): from meh import ExceptionInfo from meh.dump import ReverseExceptionDump from inspect import stack as _stack from traceback import format_stack # Skip the frames for dumpState and the signal handler. stack = _stack()[2:] stack.reverse() exn = ReverseExceptionDump(ExceptionInfo(None, None, stack), self.mehConfig) # gather up info on the running threads threads = "\nThreads\n-------\n" # Every call to sys._current_frames() returns a new dict, so it is not # modified when threads are created or destroyed. Iterating over it is # thread safe. for thread_id, frame in sys._current_frames().items(): threads += "\nThread %s\n" % (thread_id,) threads += "".join(format_stack(frame)) # dump to a unique file (fd, filename) = mkstemp(prefix="anaconda-tb-", dir="/tmp") dump_text = exn.traceback_and_object_dump(self) dump_text += threads dump_text_bytes = dump_text.encode("utf-8") os.write(fd, dump_text_bytes) os.close(fd) # append to a given file with open("/tmp/anaconda-tb-all.log", "a+") as f: f.write("--- traceback: %s ---\n" % filename) f.write(dump_text + "\n")
def dumpState(self): from meh import ExceptionInfo from meh.dump import ReverseExceptionDump from inspect import stack as _stack from traceback import format_stack # Skip the frames for dumpState and the signal handler. stack = _stack()[2:] stack.reverse() exn = ReverseExceptionDump(ExceptionInfo(None, None, stack), self.mehConfig) # gather up info on the running threads threads = "\nThreads\n-------\n" # Every call to sys._current_frames() returns a new dict, so it is not # modified when threads are created or destroyed. Iterating over it is # thread safe. for thread_id, frame in sys._current_frames().items(): threads += "\nThread %s\n" % (thread_id, ) threads += "".join(format_stack(frame)) # dump to a unique file (fd, filename) = mkstemp(prefix="anaconda-tb-", dir="/tmp") dump_text = exn.traceback_and_object_dump(self) dump_text += threads dump_text_bytes = dump_text.encode("utf-8") os.write(fd, dump_text_bytes) os.close(fd) # append to a given file with open("/tmp/anaconda-tb-all.log", "a+") as f: f.write("--- traceback: %s ---\n" % filename) f.write(dump_text + "\n")
def dump(self, conf, obj): from inspect import stack as _stack stack = _stack()[1:] dump = ExceptionDump(ExceptionInfo(None, None, stack), conf) return dump.dump(obj)
def dumpState(self): from meh import ExceptionInfo from meh.dump import ReverseExceptionDump from inspect import stack as _stack from traceback import format_stack # Skip the frames for dumpState and the signal handler. stack = _stack()[2:] stack.reverse() exn = ReverseExceptionDump(ExceptionInfo(None, None, stack), self.mehConfig) # gather up info on the running threads threads = "\nThreads\n-------\n" for thread_id, frame in sys._current_frames().items(): threads += "\nThread %s\n" % (thread_id,) threads += "".join(format_stack(frame)) # dump to a unique file (fd, filename) = mkstemp(prefix="anaconda-tb-", dir="/tmp") dump_text = exn.traceback_and_object_dump(self) dump_text += threads dump_text = dump_text.encode("utf-8") iutil.eintr_retry_call(os.write, fd, dump_text) iutil.eintr_retry_call(os.close, fd) # append to a given file with open("/tmp/anaconda-tb-all.log", "a+") as f: f.write("--- traceback: %s ---\n" % filename) f.write(dump_text + "\n")
def dumpState(self): from meh import ExceptionInfo from meh.dump import ReverseExceptionDump from inspect import stack as _stack from traceback import format_stack # Skip the frames for dumpState and the signal handler. stack = _stack()[2:] stack.reverse() exn = ReverseExceptionDump(ExceptionInfo(None, None, stack), self.mehConfig) # gather up info on the running threads threads = "\nThreads\n-------\n" for thread_id, frame in sys._current_frames().items(): threads += "\nThread %s\n" % (thread_id, ) threads += "".join(format_stack(frame)) # dump to a unique file (fd, filename) = mkstemp(prefix="anaconda-tb-", dir="/tmp") dump_text = exn.traceback_and_object_dump(self) dump_text += threads dump_text_bytes = dump_text.encode("utf-8") iutil.eintr_retry_call(os.write, fd, dump_text_bytes) iutil.eintr_ignore(os.close, fd) # append to a given file with open("/tmp/anaconda-tb-all.log", "a+") as f: f.write("--- traceback: %s ---\n" % filename) f.write(dump_text + "\n")
def _drop(name): """ Drop a variable from the caller's locals. """ global _df _locals = _stack()[2][0].f_locals if name in _locals and name in _df.columns: _locals.pop(name) else: raise ValueError("cannot drop variable '{}' because it is not currently loaded".format(name))
def here(worker, attrs): """Delegates attribute(s) and embeds into the containing class. :param worker: str or object; subordinate(s) to delegate to :param attrs: str or sequence of strings; attributes to delegate :return: a proxy (if one is requested), or list of proxies (if multiple requested) """ supervisor = _stack()[1].frame.f_locals logger.debug( str(dict(worker=worker, attrs=attrs, supervisor=supervisor))) return delegated.tasks(worker, attrs, supervisor=supervisor)
def dumpState(self): from meh.dump import ReverseExceptionDump from inspect import stack as _stack # Skip the frames for dumpState and the signal handler. stack = _stack()[2:] stack.reverse() exn = ReverseExceptionDump((None, None, stack), self.mehConfig) (fd, filename) = mkstemp("", "anaconda-tb-", "/tmp") fo = os.fdopen(fd, "w") exn.write(self, fo)
def _generate(name): """ Generate a new variable in the caller's locals. Test if the variable name is valid. """ _locals = _stack()[2][0].f_locals if _iskeyword(name): raise ValueError("cannot name variable '{}' because it is a Python keyword".format(name)) if name in _builtins: raise ValueError("cannot name variable '{}' because it is a Python builtin".format(name)) if name in _locals: raise ValueError("cannot name variable '{}' because that name is already in use".format(name)) if not name.isidentifier(): raise ValueError("cannot name variable '{}' because it is an invalid Python variable name".format(name)) _locals[name] = _df[name]
def dumpState(self): from meh.dump import ReverseExceptionDump from inspect import stack as _stack # Skip the frames for dumpState and the signal handler. stack = _stack()[2:] stack.reverse() exn = ReverseExceptionDump((None, None, stack), self.mehConfig) # dump to a unique file (fd, filename) = mkstemp("", "anaconda-tb-", "/tmp") fo = os.fdopen(fd, "w") exn.write(self, fo) fo.close() #append to a given file with open(filename, "r") as f: content = f.readlines() with open("/tmp/anaconda-tb-all.log", "a+") as f: f.write("--- traceback: %s ---\n" % filename) f.writelines(content)
def __exit__(self, exc_type, exc_value, traceback): where = _stack()[1][0] G = where.f_globals for k in set(G.keys()) - self.globnames: self.All[self.name][G[k]] = k
def __enter__(self): where = _stack()[1][0].f_globals self.globnames = set(where.keys()) if not self.name in self.All: self.All[self.name] = {}