A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-February/042391.html below:

[Python-Dev] thread-safe generator in standard library

[Python-Dev] thread-safe generator in standard library [Python-Dev] thread-safe generator in standard libraryTim Peters tim.one at comcast.net
Mon Feb 2 13:57:23 EST 2004
[Jewett, Jim J]
> ...
> The most obvious use case is to generate unique keys
> (as lisp gensym).

Just noting a practical hack that's often sufficient:

    import sys
    genunique = iter(xrange(sys.maxint)).next

Then each call to genunique() delivers "the next" (short) integer, and it
inherits thread safety from the global interpreter lock.

A similar effect can be gotten via

    import itertools
    genunique = itertools.count().next

and that also inherits thread safety from the GIL.

A difference is that the xrange spelling stops when it reaches sys.maxint,
but the .count spelling silently wraps around to -sys.maxint-1 then
(undetected overflow at the C level).


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4