summaryrefslogtreecommitdiff
path: root/sys/lib/python/bsddb/dbutils.py
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2021-06-14 00:00:37 +0000
committerOri Bernstein <ori@eigenstate.org>2021-06-14 00:00:37 +0000
commita73a964e51247ed169d322c725a3a18859f109a3 (patch)
tree3f752d117274d444bda44e85609aeac1acf313f3 /sys/lib/python/bsddb/dbutils.py
parente64efe273fcb921a61bf27d33b230c4e64fcd425 (diff)
python, hg: tow outside the environment.
they've served us well, and can ride off into the sunset.
Diffstat (limited to 'sys/lib/python/bsddb/dbutils.py')
-rw-r--r--sys/lib/python/bsddb/dbutils.py77
1 files changed, 0 insertions, 77 deletions
diff --git a/sys/lib/python/bsddb/dbutils.py b/sys/lib/python/bsddb/dbutils.py
deleted file mode 100644
index 6dcfdd5b5..000000000
--- a/sys/lib/python/bsddb/dbutils.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#------------------------------------------------------------------------
-#
-# Copyright (C) 2000 Autonomous Zone Industries
-#
-# License: This is free software. You may use this software for any
-# purpose including modification/redistribution, so long as
-# this header remains intact and that you do not claim any
-# rights of ownership or authorship of this software. This
-# software has been tested, but no warranty is expressed or
-# implied.
-#
-# Author: Gregory P. Smith <greg@electricrain.com>
-#
-# Note: I don't know how useful this is in reality since when a
-# DBLockDeadlockError happens the current transaction is supposed to be
-# aborted. If it doesn't then when the operation is attempted again
-# the deadlock is still happening...
-# --Robin
-#
-#------------------------------------------------------------------------
-
-
-#
-# import the time.sleep function in a namespace safe way to allow
-# "from bsddb.dbutils import *"
-#
-from time import sleep as _sleep
-
-import db
-
-# always sleep at least N seconds between retrys
-_deadlock_MinSleepTime = 1.0/128
-# 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
-
-
-def DeadlockWrap(function, *_args, **_kwargs):
- """DeadlockWrap(function, *_args, **_kwargs) - automatically retries
- function in case of a database deadlock.
-
- This is a function intended to be used to wrap database calls such
- that they perform retrys with exponentially backing off sleeps in
- between when a DBLockDeadlockError exception is raised.
-
- A 'max_retries' parameter may optionally be passed to prevent it
- from retrying forever (in which case the exception will be reraised).
-
- d = DB(...)
- d.open(...)
- DeadlockWrap(d.put, "foo", data="bar") # set key "foo" to "bar"
- """
- sleeptime = _deadlock_MinSleepTime
- max_retries = _kwargs.get('max_retries', -1)
- if _kwargs.has_key('max_retries'):
- 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)
- # exponential backoff in the sleep time
- sleeptime *= 2
- if sleeptime > _deadlock_MaxSleepTime:
- sleeptime = _deadlock_MaxSleepTime
- max_retries -= 1
- if max_retries == -1:
- raise
-
-
-#------------------------------------------------------------------------