You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
4.1 KiB

4 years ago
  1. ========
  2. queuelib
  3. ========
  4. .. image:: https://secure.travis-ci.org/scrapy/queuelib.png?branch=master
  5. :target: http://travis-ci.org/scrapy/queuelib
  6. .. image:: https://img.shields.io/codecov/c/github/scrapy/queuelib/master.svg
  7. :target: http://codecov.io/github/scrapy/queuelib?branch=master
  8. :alt: Coverage report
  9. Queuelib is a collection of persistent (disk-based) queues for Python.
  10. Queuelib goals are speed and simplicity. It was originally part of the `Scrapy
  11. framework`_ and stripped out on its own library.
  12. Note: Queuelib isn't thread-safe.
  13. Requirements
  14. ============
  15. * Python 2.7 or Python 3.3
  16. * no external library requirements
  17. Installation
  18. ============
  19. You can install Queuelib either via the Python Package Index (PyPI) or from
  20. source.
  21. To install using pip::
  22. $ pip install queuelib
  23. To install using easy_install::
  24. $ easy_install queuelib
  25. If you have downloaded a source tarball you can install it by running the
  26. following (as root)::
  27. # python setup.py install
  28. FIFO/LIFO disk queues
  29. =====================
  30. Queuelib provides FIFO and LIFO queue implementations.
  31. Here is an example usage of the FIFO queue::
  32. >>> from queuelib import FifoDiskQueue
  33. >>> q = FifoDiskQueue("queuefile")
  34. >>> q.push(b'a')
  35. >>> q.push(b'b')
  36. >>> q.push(b'c')
  37. >>> q.pop()
  38. b'a'
  39. >>> q.close()
  40. >>> q = FifoDiskQueue("queuefile")
  41. >>> q.pop()
  42. b'b'
  43. >>> q.pop()
  44. b'c'
  45. >>> q.pop()
  46. >>>
  47. The LIFO queue is identical (API-wise), but importing ``LifoDiskQueue``
  48. instead.
  49. PriorityQueue
  50. =============
  51. A discrete-priority queue implemented by combining multiple FIFO/LIFO queues
  52. (one per priority).
  53. First, select the type of queue to be used per priority (FIFO or LIFO)::
  54. >>> from queuelib import FifoDiskQueue
  55. >>> qfactory = lambda priority: FifoDiskQueue('queue-dir-%s' % priority)
  56. Then instantiate the Priority Queue with it::
  57. >>> from queuelib import PriorityQueue
  58. >>> pq = PriorityQueue(qfactory)
  59. And use it::
  60. >>> pq.push(b'a', 3)
  61. >>> pq.push(b'b', 1)
  62. >>> pq.push(b'c', 2)
  63. >>> pq.push(b'd', 2)
  64. >>> pq.pop()
  65. b'b'
  66. >>> pq.pop()
  67. b'c'
  68. >>> pq.pop()
  69. b'd'
  70. >>> pq.pop()
  71. b'a'
  72. RoundRobinQueue
  73. ===============
  74. Has nearly the same interface and implementation as a Priority Queue except
  75. that each element must be pushed with a (mandatory) key. Popping from the
  76. queue cycles through the keys "round robin".
  77. Instantiate the Round Robin Queue similarly to the Priority Queue::
  78. >>> from queuelib import RoundRobinQueue
  79. >>> rr = RoundRobinQueue(qfactory)
  80. And use it::
  81. >>> rr.push(b'a', '1')
  82. >>> rr.push(b'b', '1')
  83. >>> rr.push(b'c', '2')
  84. >>> rr.push(b'd', '2')
  85. >>> rr.pop()
  86. b'a'
  87. >>> rr.pop()
  88. b'c'
  89. >>> rr.pop()
  90. b'b'
  91. >>> rr.pop()
  92. b'd'
  93. Mailing list
  94. ============
  95. Use the `scrapy-users`_ mailing list for questions about Queuelib.
  96. Bug tracker
  97. ===========
  98. If you have any suggestions, bug reports or annoyances please report them to
  99. our issue tracker at: http://github.com/scrapy/queuelib/issues/
  100. Contributing
  101. ============
  102. Development of Queuelib happens at GitHub: http://github.com/scrapy/queuelib
  103. You are highly encouraged to participate in the development. If you don't like
  104. GitHub (for some reason) you're welcome to send regular patches.
  105. All changes require tests to be merged.
  106. Tests
  107. =====
  108. Tests are located in `queuelib/tests` directory. They can be run using
  109. `nosetests`_ with the following command::
  110. nosetests
  111. The output should be something like the following::
  112. $ nosetests
  113. .............................................................................
  114. ----------------------------------------------------------------------
  115. Ran 77 tests in 0.145s
  116. OK
  117. License
  118. =======
  119. This software is licensed under the BSD License. See the LICENSE file in the
  120. top distribution directory for the full license text.
  121. Versioning
  122. ==========
  123. This software follows `Semantic Versioning`_
  124. .. _Scrapy framework: http://scrapy.org
  125. .. _scrapy-users: http://groups.google.com/group/scrapy-users
  126. .. _Semantic Versioning: http://semver.org/
  127. .. _nosetests: https://nose.readthedocs.org/en/latest/