Called when a context is stopped or a new context is made runnable.
(prev, next)
| 170 | # _schedule_callback |
| 171 | # ======================================================================================================================= |
| 172 | def _schedule_callback(prev, next): |
| 173 | """ |
| 174 | Called when a context is stopped or a new context is made runnable. |
| 175 | """ |
| 176 | try: |
| 177 | if not prev and not next: |
| 178 | return |
| 179 | |
| 180 | current_frame = sys._getframe() |
| 181 | |
| 182 | if next: |
| 183 | register_tasklet_info(next) |
| 184 | |
| 185 | # Ok, making next runnable: set the tracing facility in it. |
| 186 | debugger = get_global_debugger() |
| 187 | if debugger is not None: |
| 188 | next.trace_function = debugger.get_thread_local_trace_func() |
| 189 | frame = next.frame |
| 190 | if frame is current_frame: |
| 191 | frame = frame.f_back |
| 192 | if hasattr(frame, "f_trace"): # Note: can be None (but hasattr should cover for that too). |
| 193 | frame.f_trace = debugger.get_thread_local_trace_func() |
| 194 | |
| 195 | debugger = None |
| 196 | |
| 197 | if prev: |
| 198 | register_tasklet_info(prev) |
| 199 | |
| 200 | try: |
| 201 | for tasklet_ref, tasklet_info in list(_weak_tasklet_registered_to_info.items()): # Make sure it's a copy! |
| 202 | tasklet = tasklet_ref() |
| 203 | if tasklet is None or not tasklet.alive: |
| 204 | # Garbage-collected already! |
| 205 | try: |
| 206 | del _weak_tasklet_registered_to_info[tasklet_ref] |
| 207 | except KeyError: |
| 208 | pass |
| 209 | if tasklet_info.frame_id is not None: |
| 210 | remove_custom_frame(tasklet_info.frame_id) |
| 211 | else: |
| 212 | is_running = stackless.get_thread_info(tasklet.thread_id)[1] is tasklet |
| 213 | if tasklet is prev or (tasklet is not next and not is_running): |
| 214 | # the tasklet won't run after this scheduler action: |
| 215 | # - the tasklet is the previous tasklet |
| 216 | # - it is not the next tasklet and it is not an already running tasklet |
| 217 | frame = tasklet.frame |
| 218 | if frame is current_frame: |
| 219 | frame = frame.f_back |
| 220 | if frame is not None: |
| 221 | # print >>sys.stderr, "SchedCB: %r, %d, '%s', '%s'" % (tasklet, frame.f_lineno, _filename, base) |
| 222 | debugger = get_global_debugger() |
| 223 | if debugger is not None and debugger.get_file_type(frame) is None: |
| 224 | tasklet_info.update_name() |
| 225 | if tasklet_info.frame_id is None: |
| 226 | tasklet_info.frame_id = add_custom_frame(frame, tasklet_info.tasklet_name, tasklet.thread_id) |
| 227 | else: |
| 228 | update_custom_frame(tasklet_info.frame_id, frame, tasklet.thread_id, name=tasklet_info.tasklet_name) |
| 229 | debugger = None |
nothing calls this directly
no test coverage detected