peter-wangxu / persist-queue

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

Get() hangs when used with pqid #189

Open w1am opened 2 years ago

w1am commented 2 years ago
from persistqueue import SQLiteQueue

q = SQLiteQueue(path="/tmp/queue", auto_commit=True)

q.put(item={ "pqid": 100, "name": "william" })

x = q.get(id={ "pqid": 100, "name": "william" })
pprint(x)

After playing around more with this I noticed that even though pqid was set in the put method. it returns the latest sequence number of the sql table i.e 1 instead of 100

I tried setting timeout=0 but it raises Empty error.

doliynyk-nference commented 1 year ago

I don't think you cannot set a custom pqid when you create your item. Take a look at q.queue() to see how your data is being stored: [{'id': 1, 'data': {'pqid': 100, 'name': 'william'}, 'timestamp': 1669919848.33653}] So you are storing a dictionary which contains a pqid entry inside it but the actual id under which your dictionary gets stored under is 1. Thus x = q.get(id={ "pqid": 100, "name": "william" }) will block indefinitely or raise and Empty error as there is no element stored that has an id of { "pqid": 100, "name": "william" } like you are asking for. On the other hand q.get(id=1) will work and return {'pqid': 100, 'name': 'william'}.