Simple thread-safe counter?

Paul Rubin http
Sat Apr 2 15:28:13 EST 2005


aahz at pythoncraft.com (Aahz) writes:
> This is one case where'd recommend using a plan RLock() instead of using
> Queue -- the RLock() will be more efficient...

I'm starting to believe the GIL covers up an awful lot of sloppiness
in Python.  I wonder if there could be a decorator approach:

    @synchronized
    def counter():
       t = itertools.count()
       while True:
         yield t.next()

or better yet,

    counter = synchronized(itertools.count())



More information about the Python-list mailing list