Synchronization decorator; provide thread-safe locking on a function
    http://code.activestate.com/recipes/465057/

def synchronized_limit(lock):
    """
    Synchronization decorator; provide thread-safe locking on a function
    http://code.activestate.com/recipes/465057/
    """
    def wrap(f):
        def synchronize(*args, **kw):
            if lock[1] < 10:
                lock[1] += 1
                lock[0].acquire()
                try:
                    return f(*args, **kw)
                finally:
                    lock[1] -= 1
                    lock[0].release()
            else:
                raise Exception('Too busy')
        return synchronize
    return wrap