Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../bsddb
File: dbutils.py
#------------------------------------------------------------------------
[0] Fix | Delete
#
[1] Fix | Delete
# Copyright (C) 2000 Autonomous Zone Industries
[2] Fix | Delete
#
[3] Fix | Delete
# License: This is free software. You may use this software for any
[4] Fix | Delete
# purpose including modification/redistribution, so long as
[5] Fix | Delete
# this header remains intact and that you do not claim any
[6] Fix | Delete
# rights of ownership or authorship of this software. This
[7] Fix | Delete
# software has been tested, but no warranty is expressed or
[8] Fix | Delete
# implied.
[9] Fix | Delete
#
[10] Fix | Delete
# Author: Gregory P. Smith <greg@krypto.org>
[11] Fix | Delete
#
[12] Fix | Delete
# Note: I don't know how useful this is in reality since when a
[13] Fix | Delete
# DBLockDeadlockError happens the current transaction is supposed to be
[14] Fix | Delete
# aborted. If it doesn't then when the operation is attempted again
[15] Fix | Delete
# the deadlock is still happening...
[16] Fix | Delete
# --Robin
[17] Fix | Delete
#
[18] Fix | Delete
#------------------------------------------------------------------------
[19] Fix | Delete
[20] Fix | Delete
[21] Fix | Delete
#
[22] Fix | Delete
# import the time.sleep function in a namespace safe way to allow
[23] Fix | Delete
# "from bsddb.dbutils import *"
[24] Fix | Delete
#
[25] Fix | Delete
from time import sleep as _sleep
[26] Fix | Delete
[27] Fix | Delete
import sys
[28] Fix | Delete
absolute_import = (sys.version_info[0] >= 3)
[29] Fix | Delete
if absolute_import :
[30] Fix | Delete
# Because this syntaxis is not valid before Python 2.5
[31] Fix | Delete
exec("from . import db")
[32] Fix | Delete
else :
[33] Fix | Delete
import db
[34] Fix | Delete
[35] Fix | Delete
# always sleep at least N seconds between retrys
[36] Fix | Delete
_deadlock_MinSleepTime = 1.0/128
[37] Fix | Delete
# never sleep more than N seconds between retrys
[38] Fix | Delete
_deadlock_MaxSleepTime = 3.14159
[39] Fix | Delete
[40] Fix | Delete
# Assign a file object to this for a "sleeping" message to be written to it
[41] Fix | Delete
# each retry
[42] Fix | Delete
_deadlock_VerboseFile = None
[43] Fix | Delete
[44] Fix | Delete
[45] Fix | Delete
def DeadlockWrap(function, *_args, **_kwargs):
[46] Fix | Delete
"""DeadlockWrap(function, *_args, **_kwargs) - automatically retries
[47] Fix | Delete
function in case of a database deadlock.
[48] Fix | Delete
[49] Fix | Delete
This is a function intended to be used to wrap database calls such
[50] Fix | Delete
that they perform retrys with exponentially backing off sleeps in
[51] Fix | Delete
between when a DBLockDeadlockError exception is raised.
[52] Fix | Delete
[53] Fix | Delete
A 'max_retries' parameter may optionally be passed to prevent it
[54] Fix | Delete
from retrying forever (in which case the exception will be reraised).
[55] Fix | Delete
[56] Fix | Delete
d = DB(...)
[57] Fix | Delete
d.open(...)
[58] Fix | Delete
DeadlockWrap(d.put, "foo", data="bar") # set key "foo" to "bar"
[59] Fix | Delete
"""
[60] Fix | Delete
sleeptime = _deadlock_MinSleepTime
[61] Fix | Delete
max_retries = _kwargs.get('max_retries', -1)
[62] Fix | Delete
if 'max_retries' in _kwargs:
[63] Fix | Delete
del _kwargs['max_retries']
[64] Fix | Delete
while True:
[65] Fix | Delete
try:
[66] Fix | Delete
return function(*_args, **_kwargs)
[67] Fix | Delete
except db.DBLockDeadlockError:
[68] Fix | Delete
if _deadlock_VerboseFile:
[69] Fix | Delete
_deadlock_VerboseFile.write(
[70] Fix | Delete
'dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime)
[71] Fix | Delete
_sleep(sleeptime)
[72] Fix | Delete
# exponential backoff in the sleep time
[73] Fix | Delete
sleeptime *= 2
[74] Fix | Delete
if sleeptime > _deadlock_MaxSleepTime:
[75] Fix | Delete
sleeptime = _deadlock_MaxSleepTime
[76] Fix | Delete
max_retries -= 1
[77] Fix | Delete
if max_retries == -1:
[78] Fix | Delete
raise
[79] Fix | Delete
[80] Fix | Delete
[81] Fix | Delete
#------------------------------------------------------------------------
[82] Fix | Delete
[83] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function