def DeadlockWrap(function, *_args, **_kwargs):
 sleeptime = _deadlock_MinSleepTime
 max_retries = _kwargs.get('max_retries', (-1))
 if ('max_retries' in _kwargs):
  del _kwargs['max_retries']
 while True:
  try:
   return function(*_args, **_kwargs)
  except db.DBLockDeadlockError:
   if _deadlock_VerboseFile:
    _deadlock_VerboseFile.write(('dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime))
   _sleep(sleeptime)
   sleeptime *= 2
   if (sleeptime > _deadlock_MaxSleepTime):
    sleeptime = _deadlock_MaxSleepTime
   max_retries -= 1
   if (max_retries == (-1)):
    raise

def DeadlockWrap ( function , * _args , ** _kwargs ) : sleeptime = _deadlock_MinSleepTime max_retries = _kwargs . get ( 'max_retries' , ( - 1 ) ) if ( 'max_retries' in _kwargs ) : del _kwargs [ 'max_retries' ] while True : try : return function ( * _args , ** _kwargs ) except db . DBLockDeadlockError : if _deadlock_VerboseFile : _deadlock_VerboseFile . write ( ( 'dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime ) ) _sleep ( sleeptime ) sleeptime *= 2 if ( sleeptime > _deadlock_MaxSleepTime ) : sleeptime = _deadlock_MaxSleepTime max_retries -= 1 if ( max_retries == ( - 1 ) ) : raise
deadlockwrap - automatically retries function in case of a database deadlock .