jodal / pykka

🌀 Pykka makes it easier to build concurrent Python applications.
https://pykka.readthedocs.io
Apache License 2.0
1.21k stars 107 forks source link

Implementation of priority queues/mailboxes #66

Open julian-r opened 8 years ago

julian-r commented 8 years ago

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

jodal commented 8 years ago

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.

lostcontrol commented 2 years ago

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.