Hi Shesha,
> Am 2016-03-12 um 08:08 schrieb Shesha Sreenivasamurthy <
she...@gmail.com>:
>
> I have a producer-consumer set up, where producer is generating objects and consumer is consuming them. I have create a Store resource: x = simpy.Store(self.env, capacity=simpy.core.Infinity)
>
> on producer I perform:
> -----------------------------
> obj = Object()
> x.put(obj)
>
> on consumer I perform:
> --------------------------------
> with x.get() as req:
> yield req
> obj = req.value
> <process object here>
"obj = yield req" would be more idiomatic in this case. Most cases (e.g, if
you don't cancel request), you can even just do "obj = yield store.get()".
> This works perfectly fine. However, I want to now add priority to the objects so if the producer produces a priority object, the consumer should get that object ahead of all the other objects producer has produced earlier. How to go about achieving this ?
>
> For example:
> ---------------------
> Producer produces objects: 'a', 'b', 'c', 'Z', 'd' at time 0,1, 2, 3 & 4. 'Z' has higher priority than 'a', 'b', 'c' and 'd'.
You could implement a new subclass of Store, where you override "_do_get()".
Instead of returning the first element as "Store" does, you could return the
element with the highest priority currently in the store. You can also use
the FilterStore as a source of inspiration :)
Cheers,
Stefan
>
> Say, consumer needs 2 seconds to process each object. At time 0 and 2 consumer process objects 'a' and 'b'. By the time consumer is ready to process its 3rd object (at time 4), producer has produced high priority object 'Z'. Therefore, consumer should process 'Z' before 'c'. How to achieve this ?
>
> --
> You received this message because you are subscribed to the Google Groups "python-simpy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
python-simpy...@googlegroups.com.
> To post to this group, send email to
python...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/python-simpy/57b52cd9-ba6c-42ce-95cb-1ab7703dfc6e%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.