def counter():
 lock = compat.threading.Lock()
 counter = itertools.count(1)
 def _next():
  lock.acquire()
  try:
   return next(counter)
  finally:
   lock.release()
 return _next

def counter ( ) : lock = compat . threading . Lock ( ) counter = itertools . count ( 1 ) def _next ( ) : lock . acquire ( ) try : return next ( counter ) finally : lock . release ( ) return _next
every time you reload .