diff options
author | Barry Warsaw <barry@python.org> | 2002-12-30 20:53:52 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2002-12-30 20:53:52 (GMT) |
commit | 9a0d779c7d39ba5f4666eac7c3f913720198e0f8 (patch) | |
tree | 1c4c47178b74e5b8564c625d79a940107c217b04 /Lib/bsddb/dbutils.py | |
parent | 0a26235e671064ddda5625c1981aa2edf91bb7a8 (diff) | |
download | cpython-9a0d779c7d39ba5f4666eac7c3f913720198e0f8.zip cpython-9a0d779c7d39ba5f4666eac7c3f913720198e0f8.tar.gz cpython-9a0d779c7d39ba5f4666eac7c3f913720198e0f8.tar.bz2 |
Port BerkeleyDB 4.1 support from the pybsddb project. bsddb is now at
version 4.1.1 and works with up to BerkeleyDB 4.1.25.
Diffstat (limited to 'Lib/bsddb/dbutils.py')
-rw-r--r-- | Lib/bsddb/dbutils.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/Lib/bsddb/dbutils.py b/Lib/bsddb/dbutils.py index 81b6d8a..7328ca7 100644 --- a/Lib/bsddb/dbutils.py +++ b/Lib/bsddb/dbutils.py @@ -22,19 +22,21 @@ # # import the time.sleep function in a namespace safe way to allow -# "from bsddb3.db import *" +# "from bsddb.db import *" # -from time import sleep -_sleep = sleep -del sleep +from time import sleep as _sleep -import _bsddb +from bsddb import _db -_deadlock_MinSleepTime = 1.0/64 # always sleep at least N seconds between retrys -_deadlock_MaxSleepTime = 3.14159 # never sleep more than N seconds between retrys +# always sleep at least N seconds between retrys +_deadlock_MinSleepTime = 1.0/64 +# never sleep more than N seconds between retrys +_deadlock_MaxSleepTime = 3.14159 + +# Assign a file object to this for a "sleeping" message to be written to it +# each retry +_deadlock_VerboseFile = None -_deadlock_VerboseFile = None # Assign a file object to this for a "sleeping" - # message to be written to it each retry def DeadlockWrap(function, *_args, **_kwargs): """DeadlockWrap(function, *_args, **_kwargs) - automatically retries @@ -57,16 +59,17 @@ def DeadlockWrap(function, *_args, **_kwargs): del _kwargs['max_retries'] while 1: try: - return apply(function, _args, _kwargs) - except _bsddb.DBLockDeadlockError: + return function(*_args, **_kwargs) + except _db.DBLockDeadlockError: if _deadlock_VerboseFile: - _deadlock_VerboseFile.write('dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime) + _deadlock_VerboseFile.write( + 'dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime) _sleep(sleeptime) # exponential backoff in the sleep time - sleeptime = sleeptime * 2 - if sleeptime > _deadlock_MaxSleepTime : + sleeptime *= 2 + if sleeptime > _deadlock_MaxSleepTime: sleeptime = _deadlock_MaxSleepTime - max_retries = max_retries - 1 + max_retries -= 1 if max_retries == -1: raise |