Skip to main content

These classes and functions provide the facility to close a queue and to use it as an iterator.

Project description

This package is a fork of CloseableQueue. The goal of this fork is to provide an implementation of CloseableQueue that is compatible with both Python 2 and Python 3.

CloseableQueue

The CloseableQueue module includes the Closeable*Queue classes as well as the Closed exception and some utility functions.

These classes and functions provide the facility to close a queue and to use it as an iterator.

The Closeable*Queue classes

The CloseableQueue class adds to Queue.Queue the means to permanently close a queue.

This is intended to provide queue support for functionality that would otherwise be implemented through the use of sentinel values or other mechanisms. Such workarounds can be particularly awkward in the case of multi-consumer queues.

CloseableQueue class provides both a close method and an extra parameter, last, to its put method.

CloseableLifoQueue and CloseablePriorityQueue are similar classes which subclass Queue.LifoQueue and Queue.PriorityQueue respectively.

Further details are available in the docstrings of the classes and their methods.

CloseableQueueFactory

This factory function is used to create the Closeable*Queue classes.

This approach is used instead of a mixin class because the Queue module’s classes are old-style.

It should be possible to apply this function to other Queue-derived classes, as long as they have not overridden get or put (or defined close or closed).

For example:

>>> CloseableFooQueue = CloseableQueueFactory(FooQueue,
...                                           "CloseableFooQueue")

The Closed exception class

Both the get and put methods of a CloseableQueue object may raise Closed if called on a closed queue.

Note that get will only raise Closed if the queue is empty.

Iteration utility functions

Transformation of iterables to and from queues is made convenient via the enqueue and dequeue functions.

The EnqueueThread function provides a further layer of convenience.

Although designed to work with closeable queues, these functions can also be meaningfully applied to other Queues.

See their docstrings for more information.

Tests

The CloseableQueue test suite is based on, and reuses much of the code from, the test suite for the standard library’s Queue module.

Regression tests are performed on the CloseableQueue class, in addition to tests of the closing functionality.

Although the tests are reasonably thorough, the author is by no means an expert in the area of concurrency; review by more experienced developers is quite welcome.

The test suite may provide guidance in the form of simplistic usage examples.

Some attempt has been made to write code which will work on older Pythons, however testing has only been performed on Python 2.6, and the author has little experience with older versions.

Distribution

CloseableQueue-py3 is available on PyPI and from the GitHub repository.

The package from which CloseableQueue-py3 was forked, CloseableQueue, is also available on PyPI and from its own repository on GitHub.

License

The CloseableQueue module is licensed under the permissive terms of the FreeBSD license.

See the file COPYING for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

CloseableQueue-py3-0.9.2.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

CloseableQueue_py3-0.9.2-py2.py3-none-any.whl (23.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file CloseableQueue-py3-0.9.2.tar.gz.

File metadata

  • Download URL: CloseableQueue-py3-0.9.2.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.0

File hashes

Hashes for CloseableQueue-py3-0.9.2.tar.gz
Algorithm Hash digest
SHA256 398d462320e162c61b730c747e597d4b76979d5846d762c60230d2128af284a6
MD5 d63f39f980f349a36a9d76df87d61362
BLAKE2b-256 a5903b663008c325b52ad12549fa93312dd74594c23711722e55503b7e1dc8fc

See more details on using hashes here.

File details

Details for the file CloseableQueue_py3-0.9.2-py2.py3-none-any.whl.

File metadata

  • Download URL: CloseableQueue_py3-0.9.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.0

File hashes

Hashes for CloseableQueue_py3-0.9.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c5cebe58b249042b257e4267ccf8c61a86fe927f3e3b96981c66a5c767a81d2d
MD5 ef64ef26f937e97dcdbc3037299d25f0
BLAKE2b-256 6104f067429f1ff6416fc3e8bee73650a6b81aeb63f6d7f218226dc34eb736b9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page