[Numpy-discussion] numpy/Windows shared arrays between processes?
Wed Oct 10 13:57:10 CDT 2007
At 10:00 AM 10/10/2007, Robert Kern wrote:
>Something like the following should suffice (untested, though
I've >done similar things with ctypes before):
I tested, successfully:
def fromaddress(address, dtype, shape, strides=None):
""" Create a numpy array from an integer address, a dtype
or dtype string, a shape tuple, and possibly strides.
# Make sure our dtype is a dtype, not just "f" or whatever.
dtype = numpy.dtype(dtype)
d = Dummy()
d.__array_interface__ = dict(
data = (address, False),
typestr = dtype.str,
descr = dtype.descr,
shape = shape,
strides = strides,
version = 3,
## Numeric example, with address kludge
import Numeric, numpy, ctypes, string
a0 = Numeric.zeros((10000), Numeric.Int16)
nAddress = int(string.split(repr(a0.__copy__))[-1][:-1], 16)
ctypes.memmove(tmp, nAddress+8, 4)
nAddress = tmp
a1 = fromaddress(nAddress, numpy.int16, (10000,)) ## explicit type
a0 = 5
## numpy example
a2 = numpy.zeros(10000, numpy.int16)
nAddress = a2.__array_interface__['data']
nType = a2.__array_interface__['typestr']
nShape = a2.__array_interface__['shape']
a3 = fromaddress(nAddress, nType, nShape)
a2 = 5
So, now with little effort the relevant info can be passed over
pipes, shared memory, etc. and shares/views created in other
processes, since they are not objects but ints and strings.
>David Cournapeau Wrote:
>Basically, you cannot expect file descriptors (or even file
>standard ones from C library fopen) to cross dll boundaries if
the >dll do not have exactly the same runtime.
It sounds like there is a general dilemma: no one with Python 2.4 or
2.5 can reliably expect to compile extensions/modules if they did not
install the 7.1 compiler in time.
The 2.6 seems to use VC 2005 Express, I don't know about py3000(?),
with associated upgrade issues.
It would be nice if the build bots could also compile suggested
More information about the Numpy-discussion