MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / _PrioritizedWorkItem

Class _PrioritizedWorkItem

dwave/cloud/concurrency.py:49–77  ·  view source on GitHub ↗

Extension of :class:`_PriorityOrderedItem` that handles execution priority passed in `kwargs` of :class:`concurrent.futures.thread._WorkItem` items.

Source from the content-addressed store, hash-verified

47
48
49class _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
80class _PrioritizingQueue(queue.PriorityQueue):

Callers 4

test_constructionMethod · 0.90
test_prioritizationMethod · 0.90
putMethod · 0.85

Calls

no outgoing calls

Tested by 3

test_constructionMethod · 0.72
test_prioritizationMethod · 0.72