<s> from time import sleep as _sleep <EOL> import db <EOL> _deadlock_MinSleepTime = <NUM_LIT:1.0> / <NUM_LIT> <EOL> _deadlock_MaxSleepTime = <NUM_LIT> <EOL> _deadlock_VerboseFile = None <EOL> def DeadlockWrap ( function , * _args , ** _kwargs ) : <EOL> """<STR_LIT>""" <EOL> sleeptime = _deadlock_MinSleepTime <EOL> max_retries = _kwargs . get ( '<STR_LIT>' , - <NUM_LIT:1> ) <EOL> if _kwargs . has_key ( '<STR_LIT>' ) : <EOL> del _kwargs [ '<STR_LIT>' ] <EOL> while True : <EOL> try : <EOL> return function ( * _args , ** _kwargs ) <EOL> except db . DBLockDeadlockError : <EOL> if _deadlock_VerboseFile : <EOL> _deadlock_VerboseFile . write ( <EOL> '<STR_LIT>' % sleeptime ) <EOL> _sleep ( sleeptime ) <EOL> sleeptime *= <NUM_LIT:2> <EOL> if sleeptime > _deadlock_MaxSleepTime : <EOL> sleeptime = _deadlock_MaxSleepTime <EOL> max_retries -= <NUM_LIT:1> <EOL> if max_retries == - <NUM_LIT:1> : <EOL> raise </s>
