pykka icon indicating copy to clipboard operation
pykka copied to clipboard

Implementation of priority queues/mailboxes

Open julian-r opened this issue 9 years ago • 2 comments

I had the need for a priority mailbox. I implemented priority queues pretty raw with touching the core part as less as possible.

For the tell ask messages it looks like that:

actor_ref.ask({'pykka_priority': 10, 'num': 1})

For proxies it is usable with a small decorator:

class AnProxyActor(ThreadingActorPriorityMailbox):
    def __init__(self):
        ThreadingActorPriorityMailbox.__init__(self)
        self.call_order = []

    @priority(40)
    def important(self):
        time.sleep(0.4)
        self.call_order.append('important')

    @priority(30)
    def more_important(self):
        time.sleep(0.4)
        self.call_order.append('more_important')

Looking forward to your feedback.

Its here: https://github.com/julian-r/pykka/tree/priority_queue

julian-r avatar Feb 16 '16 17:02 julian-r

Without looking at the code, I find this interesting as a use case for what should be possible to do without altering Pykka itself. Setting this to milestone v2.0 to revisit it later.

jodal avatar Feb 16 '16 20:02 jodal

Without looking at the code, I find this interesting as a use case for what should be possible to do without altering Pykka itself. Setting this to milestone v2.0 to revisit it later.

I wonder how it would be possible to do this without altering Pykka at all!? In any case, this is an interesting feature that we could use. In our case, we can have x,x,x,x,x,x in the queue and want y to be served as soon as possible, mainly to interrupt any further processing of x.

lostcontrol avatar Oct 08 '21 18:10 lostcontrol