Simpy: Possible to do priority requests with filterstore?

試著忘記壹切 提交于 2021-01-29 06:00:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!