thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

Memmap with multiprocessing in Windows (migrated from Trac #1809) #3357

Open thouis opened 12 years ago

thouis commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/1809 Reported 2011-04-27 by trac user tfmoraes, assigned to unknown.

Running the following code https://gist.github.com/929168 in Windows (I've tested only in XP) a AttributeError exception happens, here a more detailed traceback https://gist.github.com/944144 .

That code creates a new python process via multiprocessing to run a function, the parameter to this function is a memmap array created by the main process. This code works with the last numpy stable version in Linux and Mac OS X, but in Windows. Numpy version 1.4.1 runs correctly that code in Windows, Linux and Mac OS X.

thouis commented 12 years ago

Comment in Trac by atmention:rgommers, 2011-04-28

From the ML (cgohlke): I don't think this was working correctly in numpy 1.4 either. The underlying problem seems to be that instance attributes of ndarray subtypes get lost during pickling:

import pickle
import numpy as np
class aarray(np.ndarray):
    def __new__(subtype):
        self = np.ndarray.__new__(subtype, (1,))
        self.attr = 'attr'
        return self
    def __array_finalize__(self, obj):
        self.attr = getattr(obj, 'attr', None)
a = aarray()
b = pickle.loads(a.dumps())
assert a.attr == b.attr, (a.attr, b.attr)

AssertionError: ('attr', None)