| 43 | # _TaskletInfo |
| 44 | # ======================================================================================================================= |
| 45 | class _TaskletInfo: |
| 46 | _last_id = 0 |
| 47 | |
| 48 | def __init__(self, tasklet_weakref, tasklet): |
| 49 | self.frame_id = None |
| 50 | self.tasklet_weakref = tasklet_weakref |
| 51 | |
| 52 | last_id = _tasklet_to_last_id.get(tasklet) |
| 53 | if last_id is None: |
| 54 | _TaskletInfo._last_id += 1 |
| 55 | last_id = _TaskletInfo._last_id |
| 56 | _tasklet_to_last_id[tasklet] = last_id |
| 57 | |
| 58 | self._tasklet_id = last_id |
| 59 | |
| 60 | self.update_name() |
| 61 | |
| 62 | def update_name(self): |
| 63 | tasklet = self.tasklet_weakref() |
| 64 | if tasklet: |
| 65 | if tasklet.blocked: |
| 66 | state = "blocked" |
| 67 | elif tasklet.paused: |
| 68 | state = "paused" |
| 69 | elif tasklet.scheduled: |
| 70 | state = "scheduled" |
| 71 | else: |
| 72 | state = "<UNEXPECTED>" |
| 73 | |
| 74 | try: |
| 75 | name = tasklet.name |
| 76 | except AttributeError: |
| 77 | if tasklet.is_main: |
| 78 | name = "MainTasklet" |
| 79 | else: |
| 80 | name = "Tasklet-%s" % (self._tasklet_id,) |
| 81 | |
| 82 | thread_id = tasklet.thread_id |
| 83 | if thread_id != -1: |
| 84 | for thread in threading.enumerate(): |
| 85 | if thread.ident == thread_id: |
| 86 | if thread.name: |
| 87 | thread_name = "of %s" % (thread.name,) |
| 88 | else: |
| 89 | thread_name = "of Thread-%s" % (thread.name or str(thread_id),) |
| 90 | break |
| 91 | else: |
| 92 | # should not happen. |
| 93 | thread_name = "of Thread-%s" % (str(thread_id),) |
| 94 | thread = None |
| 95 | else: |
| 96 | # tasklet is no longer bound to a thread, because its thread ended |
| 97 | thread_name = "without thread" |
| 98 | |
| 99 | tid = id(tasklet) |
| 100 | tasklet = None |
| 101 | else: |
| 102 | state = "dead" |
no outgoing calls
no test coverage detected