ctypes.py_object use weakref.ref which is rejecting dict

Create issue
Issue #2061 resolved
Catstyle Lee created an issue

this is not the same as under CPython2.7.9

i am writing a script that mainly using multiprocessing to do huge calculation for speed reason i have precalculated some factors as dict i want to share the dict(~900MB) within processes, manager.dict() use too much mem(i have no idea why) so i decide to use ctypes; but it complain TypeError: cannot create weak reference to 'dict' object, at https://bitbucket.org/pypy/pypy/src/76611312113ea3ba08c89bc40dca460949743d1b/lib_pypy/_ctypes/primitive.py?at=default#cl-56

it runs well under CPython2.7.9, should it have the same behavior?

Comments (4)

  1. Armin Rigo

    It's a known issue: ctypes.py_object is a hack, but it's hard to do better. Do you have to use ctypes in the first place? If you do, an alternative design that should work: don't use py_object at all, and instead store integers in the C data structure. The integer is an index in some list of objects (here dictionaries). In this way, you also control exactly when the objects in this list are removed ("never" is fine in some cases).

  2. Log in to comment