Back to index

python3.2  3.2.2
Classes | Functions | Variables
multiprocessing.sharedctypes Namespace Reference

Classes

class  SynchronizedBase
class  Synchronized
class  SynchronizedArray
class  SynchronizedString

Functions

def _new_value
def RawValue
def RawArray
def Value
def Array
def copy
def synchronized
def reduce_ctype
def rebuild_ctype
def make_property

Variables

list __all__ = ['RawValue', 'RawArray', 'Value', 'Array', 'copy', 'synchronized']
dictionary typecode_to_type
string template
dictionary prop_cache = {}
tuple class_cache = weakref.WeakKeyDictionary()

Function Documentation

def multiprocessing.sharedctypes._new_value (   type_) [private]

Definition at line 61 of file sharedctypes.py.

00061 
00062 def _new_value(type_):
00063     size = ctypes.sizeof(type_)
00064     wrapper = heap.BufferWrapper(size)
00065     return rebuild_ctype(type_, wrapper, None)

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.sharedctypes.Array (   typecode_or_type,
  size_or_initializer,
  kwds 
)
Return a synchronization wrapper for a RawArray

Definition at line 105 of file sharedctypes.py.

00105 
00106 def Array(typecode_or_type, size_or_initializer, **kwds):
00107     '''
00108     Return a synchronization wrapper for a RawArray
00109     '''
00110     lock = kwds.pop('lock', None)
00111     if kwds:
00112         raise ValueError('unrecognized keyword argument(s): %s' % list(kwds.keys()))
00113     obj = RawArray(typecode_or_type, size_or_initializer)
00114     if lock is False:
00115         return obj
00116     if lock in (True, None):
00117         lock = RLock()
00118     if not hasattr(lock, 'acquire'):
00119         raise AttributeError("'%r' has no method 'acquire'" % lock)
00120     return synchronized(obj, lock)

Here is the call graph for this function:

Definition at line 121 of file sharedctypes.py.

00121 
00122 def copy(obj):
00123     new_obj = _new_value(type(obj))
00124     ctypes.pointer(new_obj)[0] = obj
00125     return new_obj

Here is the call graph for this function:

Definition at line 169 of file sharedctypes.py.

00169 
00170 def make_property(name):
00171     try:
00172         return prop_cache[name]
00173     except KeyError:
00174         d = {}
00175         exec(template % ((name,)*7), d)
00176         prop_cache[name] = d[name]
00177         return d[name]

Here is the caller graph for this function:

def multiprocessing.sharedctypes.RawArray (   typecode_or_type,
  size_or_initializer 
)
Returns a ctypes array allocated from shared memory

Definition at line 76 of file sharedctypes.py.

00076 
00077 def RawArray(typecode_or_type, size_or_initializer):
00078     '''
00079     Returns a ctypes array allocated from shared memory
00080     '''
00081     type_ = typecode_to_type.get(typecode_or_type, typecode_or_type)
00082     if isinstance(size_or_initializer, int):
00083         type_ = type_ * size_or_initializer
00084         obj = _new_value(type_)
00085         ctypes.memset(ctypes.addressof(obj), 0, ctypes.sizeof(obj))
00086         return obj
00087     else:
00088         type_ = type_ * len(size_or_initializer)
00089         result = _new_value(type_)
00090         result.__init__(*size_or_initializer)
00091         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.sharedctypes.RawValue (   typecode_or_type,
  args 
)
Returns a ctypes object allocated from shared memory

Definition at line 66 of file sharedctypes.py.

00066 
00067 def RawValue(typecode_or_type, *args):
00068     '''
00069     Returns a ctypes object allocated from shared memory
00070     '''
00071     type_ = typecode_to_type.get(typecode_or_type, typecode_or_type)
00072     obj = _new_value(type_)
00073     ctypes.memset(ctypes.addressof(obj), 0, ctypes.sizeof(obj))
00074     obj.__init__(*args)
00075     return obj

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.sharedctypes.rebuild_ctype (   type_,
  wrapper,
  length 
)

Definition at line 157 of file sharedctypes.py.

00157 
00158 def rebuild_ctype(type_, wrapper, length):
00159     if length is not None:
00160         type_ = type_ * length
00161     ForkingPickler.register(type_, reduce_ctype)
00162     obj = type_.from_address(wrapper.get_address())
00163     obj._wrapper = wrapper
00164     return obj
00165 
00166 #
00167 # Function to create properties
00168 #

Here is the caller graph for this function:

Definition at line 150 of file sharedctypes.py.

00150 
00151 def reduce_ctype(obj):
00152     assert_spawning(obj)
00153     if isinstance(obj, ctypes.Array):
00154         return rebuild_ctype, (obj._type_, obj._wrapper, obj._length_)
00155     else:
00156         return rebuild_ctype, (type(obj), obj._wrapper, None)

Here is the call graph for this function:

def multiprocessing.sharedctypes.synchronized (   obj,
  lock = None 
)

Definition at line 126 of file sharedctypes.py.

00126 
00127 def synchronized(obj, lock=None):
00128     assert not isinstance(obj, SynchronizedBase), 'object already synchronized'
00129 
00130     if isinstance(obj, ctypes._SimpleCData):
00131         return Synchronized(obj, lock)
00132     elif isinstance(obj, ctypes.Array):
00133         if obj._type_ is ctypes.c_char:
00134             return SynchronizedString(obj, lock)
00135         return SynchronizedArray(obj, lock)
00136     else:
00137         cls = type(obj)
00138         try:
00139             scls = class_cache[cls]
00140         except KeyError:
00141             names = [field[0] for field in cls._fields_]
00142             d = dict((name, make_property(name)) for name in names)
00143             classname = 'Synchronized' + cls.__name__
00144             scls = class_cache[cls] = type(classname, (SynchronizedBase,), d)
00145         return scls(obj, lock)
00146 
00147 #
00148 # Functions for pickling/unpickling
00149 #

Here is the call graph for this function:

Here is the caller graph for this function:

def multiprocessing.sharedctypes.Value (   typecode_or_type,
  args,
  lock = None 
)
Return a synchronization wrapper for a Value

Definition at line 92 of file sharedctypes.py.

00092 
00093 def Value(typecode_or_type, *args, lock=None):
00094     '''
00095     Return a synchronization wrapper for a Value
00096     '''
00097     obj = RawValue(typecode_or_type, *args)
00098     if lock is False:
00099         return obj
00100     if lock in (True, None):
00101         lock = RLock()
00102     if not hasattr(lock, 'acquire'):
00103         raise AttributeError("'%r' has no method 'acquire'" % lock)
00104     return synchronized(obj, lock)

Here is the call graph for this function:


Variable Documentation

Definition at line 42 of file sharedctypes.py.

Definition at line 195 of file sharedctypes.py.

Definition at line 194 of file sharedctypes.py.

Initial value:
00001 '''
00002 def get%s(self):
00003     self.acquire()
00004     try:
00005         return self._obj.%s
00006     finally:
00007         self.release()
00008 def set%s(self, value):
00009     self.acquire()
00010     try:
00011         self._obj.%s = value
00012     finally:
00013         self.release()
00014 %s = property(get%s, set%s)
00015 '''

Definition at line 178 of file sharedctypes.py.

Initial value:
00001 {
00002     'c': ctypes.c_char,  'u': ctypes.c_wchar,
00003     'b': ctypes.c_byte,  'B': ctypes.c_ubyte,
00004     'h': ctypes.c_short, 'H': ctypes.c_ushort,
00005     'i': ctypes.c_int,   'I': ctypes.c_uint,
00006     'l': ctypes.c_long,  'L': ctypes.c_ulong,
00007     'f': ctypes.c_float, 'd': ctypes.c_double
00008     }

Definition at line 48 of file sharedctypes.py.