问题
I have a get request for one of two objects inside a filterstore that looks like this:
req = yield depot.get(lambda req: req['id'] == 's38' or 's39')
I want to make this particular request a priority so that it queue jumps all other requests. Is this possible?
回答1:
Yes, this is possible if you create a sub-class of FilterStore similarly to PriorityQueue.
回答2:
Here is an example that worked for me
import simpy
import bisect
class PriorityFilterStore(simpy.FilterStore):
def _do_put(self, event):
if len(self.items) < self._capacity:
bisect.insort(self.items, event.item)
event.succeed()
def _do_get(self, event):
for i in range(len(self.items)):
item = self.items[i]
if event.filter(item):
del self.items[i]
event.succeed(item)
break
return True
来源:https://stackoverflow.com/questions/42861279/simpy-possible-to-do-priority-requests-with-filterstore