<s> from flask import current_app <EOL> from functools import wraps <EOL> from hashlib import md5 <EOL> from changes . ext . redis import UnableToGetLock <EOL> from changes . config import redis <EOL> def lock ( func ) : <EOL> @ wraps ( func ) <EOL> def wrapped ( ** kwargs ) : <EOL> key = '<STR_LIT>' . format ( <EOL> func . __module__ , <EOL> func . __name__ , <EOL> md5 ( <EOL> '<STR_LIT:&>' . join ( '<STR_LIT>' . format ( k , repr ( v ) ) <EOL> for k , v in sorted ( kwargs . iteritems ( ) ) ) <EOL> ) . hexdigest ( ) <EOL> ) <EOL> try : <EOL> with redis . lock ( key , expire = <NUM_LIT> , nowait = True ) : <EOL> return func ( ** kwargs ) <EOL> except UnableToGetLock : <EOL> current_app . logger . warn ( '<STR_LIT>' , key ) <EOL> return wrapped </s>
