persist-queue icon indicating copy to clipboard operation
persist-queue copied to clipboard

Priority queue

Open ancieg opened this issue 2 years ago • 4 comments

I haven't found any other active Python projects for managing persistent queues (only little-functional or nearly archived ones). But this has a disadvantage (important for me) - it does not have priority queues.

I would be very happy if you add support for priority queues.

ancieg avatar Aug 13 '22 19:08 ancieg

Yes Please. I really need this too. @Ancieg did you find anything?

AGandhiCraniUS avatar Feb 06 '24 18:02 AGandhiCraniUS

I am planning to add this in next week, can you explain the use case for your scenario?

peter-wangxu avatar Feb 08 '24 03:02 peter-wangxu

Wow. That's great. My use case is for multiple data streams coming from a sensor that goes into python and needs to be stored (sorted by timestamp) and then retrieved for a server request. The priority queue allows me to have those streams be sorted at the time of insertion

AGandhiCraniUS avatar Feb 08 '24 14:02 AGandhiCraniUS

@AGandhiCraniUS If you want a Timestamp based priority queue, you can try FILOSQLiteQueue which is in First In Last out order. this is very similar to PriorityQueue which use Timestamp as the priority key, here is the example:

    def test_open_close_1000(self):
        """Write 1000 items, close, reopen checking if all items are there"""

        q = FILOSQLiteQueue(self.path, auto_commit=self.auto_commit)
        for i in range(1000):
            q.put('var%d' % i)
        self.assertEqual(1000, q.qsize())
        del q
        q = FILOSQLiteQueue(self.path)
        self.assertEqual(1000, q.qsize())
        for i in range(1000):
            data = q.get()
            self.assertEqual('var%d' % (999 - i), data)
        # assert adding another one still works
        q.put('foobar')
        data = q.get()
        self.assertEqual('foobar', data)

peter-wangxu avatar Feb 18 '24 06:02 peter-wangxu