This function extracts stacktrace without file system access by purely using sys._getframe() and removes part that belongs to this file (core.py). We are not using inspect module because its just a wrapper on top of sys._getframe() whose logic is based on accessing source files
()
| 3044 | |
| 3045 | |
| 3046 | def _extract_stacktrace(): |
| 3047 | ''' |
| 3048 | This function extracts stacktrace without file system access |
| 3049 | by purely using sys._getframe() and removes part that belongs to |
| 3050 | this file (core.py). We are not using inspect module because |
| 3051 | its just a wrapper on top of sys._getframe() whose |
| 3052 | logic is based on accessing source files on disk - exactly what |
| 3053 | we are trying to avoid here. Same stands for traceback module |
| 3054 | |
| 3055 | The reason for file system access avoidance is that |
| 3056 | if code is located on an NFS, file access might be slow |
| 3057 | |
| 3058 | Function returns a list of tuples (file_name, line_number, function) |
| 3059 | ''' |
| 3060 | |
| 3061 | result = [] |
| 3062 | # Ignore top 3 layers of stack: this function, _CreateAndAddToSelf, and |
| 3063 | # whatever calls _CreateAndAddToSelf (either __getattr__ or Python) |
| 3064 | frame = sys._getframe(3) |
| 3065 | # We just go down the frame stack in a loop |
| 3066 | while frame: |
| 3067 | # Its important to extract information from the frame here |
| 3068 | # as frame's current line most probably will change later. |
| 3069 | result.append((frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name)) |
| 3070 | frame = frame.f_back |
| 3071 | return result |
| 3072 | |
| 3073 | |
| 3074 | SetPerOpEnginePref = C.set_per_op_engine_pref |
no test coverage detected
searching dependent graphs…