Package duplicity :: Module dup_threading :: Class Value
[hide private]
[frames] | no frames]

Class Value

source code


A thread-safe container of a reference to an object (but not the
object itself).

In particular this means it is safe to:

  value.set(1)

But unsafe to:

  value.get()['key'] = value

Where the latter must be done using something like:

  def _setprop():
    value.get()['key'] = value

  with_lock(value, _setprop)

Operations such as increments are best done as:

  value.transform(lambda val: val + 1)

Instance Methods [hide private]
 
__init__(self, value=None)
Initialuze with the given value.
source code
 
get(self)
Returns the value protected by this Value.
source code
 
set(self, value)
Resets the value protected by this Value.
source code
 
transform(self, fn)
Call fn with the current value as the parameter, and reset the value to the return value of fn.
source code
 
acquire(self)
Acquire this Value for mutually exclusive access.
source code
 
release(self)
Release this Value for mutually exclusive access.
source code
Method Details [hide private]

transform(self, fn)

source code 

Call fn with the current value as the parameter, and reset the value to the return value of fn.

During the execution of fn, all other access to this Value is prevented.

If fn raised an exception, the value is not reset.

Returns the value returned by fn, or raises the exception raised by fn.

acquire(self)

source code 

Acquire this Value for mutually exclusive access. Only ever needed when calling code must perform operations that cannot be done with get(), set() or transform().