def _extract_stack(limit): try: frame = sys_getframe() except ValueError: # In certain embedded cases that directly use the Python C api # to call Greenlet.spawn (e.g., uwsgi) this can raise # `ValueError: call stack is not deep enough`. This is because # the Cython stack frames for Greenlet.spawn -> # Greenlet.__init__ -> _extract_stack are all on the C level, # not the Python level. # See https://github.com/gevent/gevent/issues/1212 frame = None newest_Frame = None newer_Frame = None while limit and frame is not None: limit -= 1 older_Frame = _Frame() # Arguments are always passed to the constructor as Python objects, # meaning we wind up boxing the f_lineno just to unbox it if we pass it. # It's faster to simply assign once the object is created. older_Frame.f_code = frame.f_code older_Frame.f_lineno = get_f_lineno(frame) # pylint:disable=undefined-variable if newer_Frame is not None: newer_Frame.f_back = older_Frame newer_Frame = older_Frame if newest_Frame is None: newest_Frame = newer_Frame frame = get_f_back(frame) # pylint:disable=undefined-variable return newest_Frame
def _extract_stack(limit): try: frame = sys_getframe() except ValueError: # In certain embedded cases that directly use the Python C api # to call Greenlet.spawn (e.g., uwsgi) this can raise # `ValueError: call stack is not deep enough`. This is because # the Cython stack frames for Greenlet.spawn -> # Greenlet.__init__ -> _extract_stack are all on the C level, # not the Python level. # See https://github.com/gevent/gevent/issues/1212 frame = None newest_Frame = None newer_Frame = None while limit and frame is not None: limit -= 1 older_Frame = _Frame() # Arguments are always passed to the constructor as Python objects, # meaning we wind up boxing the f_lineno just to unbox it if we pass it. # It's faster to simply assign once the object is created. older_Frame.f_code = frame.f_code older_Frame.f_lineno = get_f_lineno(frame) # pylint:disable=undefined-variable if newer_Frame is not None: newer_Frame.f_back = older_Frame newer_Frame = older_Frame if newest_Frame is None: newest_Frame = newer_Frame frame = get_f_back(frame) # pylint:disable=undefined-variable return newest_Frame
def _extract_stack(limit): frame = sys_getframe() frames = [] while limit and frame is not None: limit -= 1 frames.append((frame.f_code, frame.f_lineno)) frame = frame.f_back return frames
def details(self, msg, depth=2): """ encapsulate the message to write into log file """ frame = sys_getframe(depth) cur_file = ospath.basename(frame.f_code.co_filename) linenum = '' if frame.f_back is not None: linenum = frame.f_back.f_lineno info = "%s - %s line:%s" % (cur_file, frame.f_code.co_name, linenum) return "%s | %s" % (info, msg)
def _extract_stack(limit): try: frame = sys_getframe() except ValueError: # In certain embedded cases that directly use the Python C api # to call Greenlet.spawn (e.g., uwsgi) this can raise # `ValueError: call stack is not deep enough`. This is because # the Cython stack frames for Greenlet.spawn -> # Greenlet.__init__ -> _extract_stack are all on the C level, # not the Python level. # See https://github.com/gevent/gevent/issues/1212 frame = None frames = [] while limit and frame is not None: limit -= 1 frames.append((frame.f_code, frame.f_lineno)) frame = frame.f_back return frames
def _extract_stack(limit): try: frame = sys_getframe() except ValueError: # In certain embedded cases that directly use the Python C api # to call Greenlet.spawn (e.g., uwsgi) this can raise # `ValueError: call stack is not deep enough`. This is because # the Cython stack frames for Greenlet.spawn -> # Greenlet.__init__ -> _extract_stack are all on the C level, # not the Python level. # See https://github.com/gevent/gevent/issues/1212 frame = None frames = [] while limit and frame is not None: limit -= 1 frames.append((frame.f_code, frame.f_lineno)) frame = frame.f_back return frames
def get_current_func_info_by_sys(logger=None) -> None: """ 通过sys获取执行信息并打印 :param logger: :return: """ now_frame = sys_getframe() _print( msg='-> file_path: {}, func_name: {} in line_num: {} invoked'.format( # 获取被调用函数所在模块文件名 now_frame.f_code.co_filename, # 获取被调用函数名称 now_frame.f_code.co_name, # 获取被调用函数在被调用时所处代码行数 now_frame.f_back.f_lineno, ), logger=logger, log_level=1, ) return None