diff options
author | Jesus Cea <jcea@jcea.es> | 2008-08-31 14:12:11 (GMT) |
---|---|---|
committer | Jesus Cea <jcea@jcea.es> | 2008-08-31 14:12:11 (GMT) |
commit | 6ba3329c274e2c7876c61f2e98d4592310d26bae (patch) | |
tree | 6bb346e892269279fa2011c3e4bd4648b273a7ae /Lib/bsddb/dbutils.py | |
parent | 73c96dbf34c70bbf1ef807b98d51cf9c0e9dc042 (diff) | |
download | cpython-6ba3329c274e2c7876c61f2e98d4592310d26bae.zip cpython-6ba3329c274e2c7876c61f2e98d4592310d26bae.tar.gz cpython-6ba3329c274e2c7876c61f2e98d4592310d26bae.tar.bz2 |
bsddb code updated to version 4.7.3pre2. This code is the same than
Python 2.6 one, since the intention is to keep an unified 2.x/3.x
codebase.
The Python code is automatically translated using "2to3". Please, do not
update this code in Python 3.0 by hand. Update the 2.6 one and then do
"2to3".
Diffstat (limited to 'Lib/bsddb/dbutils.py')
-rw-r--r-- | Lib/bsddb/dbutils.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/Lib/bsddb/dbutils.py b/Lib/bsddb/dbutils.py index 94641ed..f401153 100644 --- a/Lib/bsddb/dbutils.py +++ b/Lib/bsddb/dbutils.py @@ -19,8 +19,20 @@ # #------------------------------------------------------------------------ -import time -from . import db + +# +# import the time.sleep function in a namespace safe way to allow +# "from bsddb.dbutils import *" +# +from time import sleep as _sleep + +import sys +absolute_import = (sys.version_info[0] >= 3) +if absolute_import : + # Because this syntaxis is not valid before Python 2.5 + exec("from . import db") +else : + from . import db # always sleep at least N seconds between retrys _deadlock_MinSleepTime = 1.0/128 @@ -54,22 +66,17 @@ def DeadlockWrap(function, *_args, **_kwargs): while True: try: return function(*_args, **_kwargs) - except db.DBLockDeadlockError as e: + except db.DBLockDeadlockError: if _deadlock_VerboseFile: _deadlock_VerboseFile.write( - 'bsddb.dbutils.DeadlockWrap: ' + - 'sleeping %1.3f\n' % sleeptime) - time.sleep(sleeptime) + 'dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime) + _sleep(sleeptime) # exponential backoff in the sleep time sleeptime *= 2 if sleeptime > _deadlock_MaxSleepTime: sleeptime = _deadlock_MaxSleepTime max_retries -= 1 if max_retries == -1: - if _deadlock_VerboseFile: - _deadlock_VerboseFile.write( - 'bsddb.dbutils.DeadlockWrap: ' + - 'max_retries reached, reraising %s\n' % e) raise |