|
1 | 1 | from python25 cimport PyFrameObject, PyObject, PyStringObject |
2 | 2 |
|
| 3 | +import threading |
3 | 4 |
|
4 | 5 | cdef extern from "frameobject.h": |
5 | 6 | ctypedef int (*Py_tracefunc)(object self, PyFrameObject *py_frame, int what, PyObject *arg) |
@@ -108,15 +109,15 @@ cdef class LineProfiler: |
108 | 109 | cdef public dict code_map |
109 | 110 | cdef public dict last_time |
110 | 111 | cdef public double timer_unit |
111 | | - cdef public long enable_count |
| 112 | + cdef public object threaddata |
112 | 113 | cdef public bint profile_all |
113 | 114 |
|
114 | 115 | def __init__(self, *functions): |
115 | 116 | self.functions = [] |
116 | 117 | self.code_map = {} |
117 | 118 | self.last_time = {} |
118 | 119 | self.timer_unit = hpTimerUnit() |
119 | | - self.enable_count = 0 |
| 120 | + self.threaddata = threading.local() |
120 | 121 | self.profile_all = False |
121 | 122 | for func in functions: |
122 | 123 | self.add_function(func) |
@@ -144,6 +145,14 @@ cdef class LineProfiler: |
144 | 145 | """ |
145 | 146 | self.profile_all = False |
146 | 147 |
|
| 148 | + property enable_count: |
| 149 | + def __get__(self): |
| 150 | + if not hasattr(self.threaddata, 'enable_count'): |
| 151 | + self.threaddata.enable_count = 0 |
| 152 | + return self.threaddata.enable_count |
| 153 | + def __set__(self, value): |
| 154 | + self.threaddata.enable_count = value |
| 155 | + |
147 | 156 | def enable_by_count(self): |
148 | 157 | """ Enable the profiler if it hasn't been enabled before. |
149 | 158 | """ |
|
0 commit comments