Message129809
> Being able to pickle unbound methods is important. In my project I have
> objects that refer to unbound methods. Now these objects are
> unpickleable. I can't save them to disk and I can't use the
> multiprocessing module on them. That's a big problem.
The multiprocessing module *can* pickle bound and unbound methods (see below), but only with the multiprocessing.Process class. It does not work with Pool.map(), for example. The reason is that Process uses the special ForkingPickler that has special code to handle methods. Pool.map could be fixed IMO.
Is "ForkingPickler" enough for your needs?
==== mod.py ============
class C:
def foo(self):
print("CALLED")
==== main.py ===========
from mod import C
if __name__ == '__main__':
from multiprocessing import Process
p = Process(target=C().foo)
p.start(); p.join()
p = Process(target=C.foo, args=(C(),))
p.start(); p.join() |
|
Date |
User |
Action |
Args |
2011-03-01 21:29:15 | amaury.forgeotdarc | set | recipients:
+ amaury.forgeotdarc, lemburg, loewis, rhettinger, hinsen, exarkun, belopolsky, pitrou, alexandre.vassalotti, eric.araujo, obamausa8, daniel.urban, cool-RR |
2011-03-01 21:29:15 | amaury.forgeotdarc | set | messageid: <1299014955.28.0.462467189097.issue9276@psf.upfronthosting.co.za> |
2011-03-01 21:29:12 | amaury.forgeotdarc | link | issue9276 messages |
2011-03-01 21:29:12 | amaury.forgeotdarc | create | |
|