资 源 简 介
DirectoryQueue
A Python package providing an abstraction around a filesystem-based queue. All queue operations are atomic as they rely on directory operations, so it is commonly used as a persistent queue between services.
Example:
>>> from directory_queue.directory_queue import DirectoryQueue >>> from directory_queue.generic_queue_item import GenericQueueItem >>> import os >>> >>> qdir = "/tmp/queue" >>> os.mkdir(qdir) >>> dq = DirectoryQueue(qdir, GenericQueueItem) >>> >>> item1 = dq.newQueueItem("item1") >>> file(item1.dataFileName(), "w").write("some data") >>> item1.writeMetadata({"what": "anything", "foo": "bar"}) >>> dq.itemReady(item1) >>> >>> ready_item1 = dq.getNext() >>> md = ready_item1.readMetadata() >>> md {"what": "anything", "foo": "bar"} >>> data = file(ready_item1.da