It seems
import Queue Queue.Queue().get(timeout=10)
is keyboard interruptible (ctrl-c) whereas
import Queue Queue.Queue().get()
is not. I could always create a loop;
import Queue q = Queue() while True: try: q.get(timeout=1000) except Queue.Empty: pass
but this seems like a strange thing to do.
So, is there a way of getting an indefinitely waiting but keyboard interruptible Queue.get()?
Queueobjects have this behavior because they lock usingConditionobjects form thethreadingmodule. So your solution is really the only way to go.However, if you really want a
Queuemethod that does this, you can monkeypatch theQueueclass. For example:This would let you say
instead of
although monkeypatching is generally discouraged by the Python community in cases such as these, since a regular function seems just as good.