summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2012-05-26 21:09:59 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2012-05-26 21:09:59 (GMT)
commit26cdf1fe5b4c42336a244ad8921bc660ff6819b4 (patch)
treedebf14a29b386e8c1100856c1beb0891b75abc93 /Lib/multiprocessing
parent1a0df94db3786aac7624e9bcb6922b87d4498692 (diff)
downloadcpython-26cdf1fe5b4c42336a244ad8921bc660ff6819b4.zip
cpython-26cdf1fe5b4c42336a244ad8921bc660ff6819b4.tar.gz
cpython-26cdf1fe5b4c42336a244ad8921bc660ff6819b4.tar.bz2
Make multiprocessing's shared memory use memoryview instead of raw pointer
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r--Lib/multiprocessing/heap.py11
-rw-r--r--Lib/multiprocessing/sharedctypes.py3
2 files changed, 5 insertions, 9 deletions
diff --git a/Lib/multiprocessing/heap.py b/Lib/multiprocessing/heap.py
index 311e402..4e93c12 100644
--- a/Lib/multiprocessing/heap.py
+++ b/Lib/multiprocessing/heap.py
@@ -205,7 +205,7 @@ class Heap(object):
self._lock.release()
#
-# Class representing a chunk of an mmap -- can be inherited
+# Class representing a chunk of an mmap -- can be inherited by child process
#
class BufferWrapper(object):
@@ -218,11 +218,6 @@ class BufferWrapper(object):
self._state = (block, size)
Finalize(self, BufferWrapper._heap.free, args=(block,))
- def get_address(self):
+ def create_memoryview(self):
(arena, start, stop), size = self._state
- address, length = _multiprocessing.address_of_buffer(arena.buffer)
- assert size <= length
- return address + start
-
- def get_size(self):
- return self._state[1]
+ return memoryview(arena.buffer)[start:start+size]
diff --git a/Lib/multiprocessing/sharedctypes.py b/Lib/multiprocessing/sharedctypes.py
index e473749..6dc160b 100644
--- a/Lib/multiprocessing/sharedctypes.py
+++ b/Lib/multiprocessing/sharedctypes.py
@@ -132,7 +132,8 @@ def rebuild_ctype(type_, wrapper, length):
if length is not None:
type_ = type_ * length
ForkingPickler.register(type_, reduce_ctype)
- obj = type_.from_address(wrapper.get_address())
+ buf = wrapper.create_memoryview()
+ obj = type_.from_buffer(buf)
obj._wrapper = wrapper
return obj