In article <[EMAIL PROTECTED]>, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Paul Rubin wrote: > > Hmm (untested, like above): > > > > class Synchronized: > > def __init__(self, generator): > > self.gen = generator > > self.lock = threading.Lock() > > def next(self): > > self.lock.acquire() > > try: > > yield self.gen.next() > > finally: > > self.lock.release() > > > > synchronized_counter = Synchronized(itertools.count()) > > > > That isn't a general solution but can be convenient (if I didn't mess > > it up). Maybe there's a more general recipe somewhere. > > This code is not allowed in Python 2.4. From PEP 255: [ snip ] The code also doesn't make sense: .next() should *return* a value, not yield one. Substituting "return" for "yield" might just work for the code above. Just -- http://mail.python.org/mailman/listinfo/python-list