Extension of :class:`_PriorityOrderedItem` that handles execution priority passed in `kwargs` of :class:`concurrent.futures.thread._WorkItem` items.
| 47 | |
| 48 | |
| 49 | class _PrioritizedWorkItem(_PriorityOrderedItem): |
| 50 | """Extension of :class:`_PriorityOrderedItem` that handles execution |
| 51 | priority passed in `kwargs` of :class:`concurrent.futures.thread._WorkItem` |
| 52 | items. |
| 53 | """ |
| 54 | # TODO: reliance on python's internal/private :class:`concurrent.futures.thread._WorkItem` |
| 55 | # structure is fragile. The structure changed in py314 (for the first time since before py2), |
| 56 | # so we should rethink our approach here before it changes again. |
| 57 | |
| 58 | def __init__(self, item): |
| 59 | if not isinstance(item, concurrent.futures.thread._WorkItem): |
| 60 | raise TypeError("concurrent.futures.thread._WorkItem expected") |
| 61 | |
| 62 | # copy constructor |
| 63 | if isinstance(item, _PrioritizedWorkItem): |
| 64 | priority = item.priority |
| 65 | else: |
| 66 | if hasattr(item, 'kwargs'): |
| 67 | # python < 3.14 |
| 68 | kwargs = item.kwargs |
| 69 | elif hasattr(item, 'task'): |
| 70 | # python >= 3.14 |
| 71 | fn, args, kwargs = item.task |
| 72 | else: |
| 73 | raise TypeError("unknown concurrent.futures.thread._WorkItem structure") |
| 74 | |
| 75 | priority = kwargs.pop('priority', sys.maxsize) |
| 76 | |
| 77 | super().__init__(item, priority) |
| 78 | |
| 79 | |
| 80 | class _PrioritizingQueue(queue.PriorityQueue): |
no outgoing calls