#NEWLINE# def acquire_lock_with_timeout( conn , lockname , acquire_timeout = 10 , lock_timeout = 10 ) : #NEWLINE# #INDENT# identifier = str ( uuid . uuid4 ( ) ) #NEWLINE# lockname = ( 'lock:' + lockname ) #NEWLINE# lock_timeout = int ( math . ceil ( lock_timeout ) ) #NEWLINE# acquired = False #NEWLINE# end = ( time . time ( ) + acquire_timeout ) #NEWLINE# while ( ( time . time ( ) < end ) and ( not acquired ) ) : #NEWLINE# #INDENT# acquired = ( acquire_lock_with_timeout_lua ( conn , [ lockname ] , [ lock_timeout , identifier ] ) == 'OK' ) #NEWLINE# time . sleep ( ( 0.001 * ( not acquired ) ) ) #NEWLINE# #UNINDENT# return ( acquired and identifier )