peter-wangxu / persist-queue

A thread-safe disk based persistent queue in Python
BSD 3-Clause "New" or "Revised" License
328 stars 48 forks source link

Priority queue #186

Open Ancieg opened 2 years ago

Ancieg commented 2 years ago

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.

AGandhiCraniUS commented 7 months ago

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

peter-wangxu commented 7 months ago

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

AGandhiCraniUS commented 7 months ago

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

peter-wangxu commented 7 months ago

@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)