Author davin
Recipients Charles McEachern, davin
Date 2017-04-07.20:49:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
It looks like the first 'Called Foo.__new__' is being reported by the child (pool of 1) process and the second 'Called Foo.__new__' is being reported by the parent process.  In multiprocessing, because objects are by default serialized using pickle, this may be caused by the unpickling of the Foo object by the parent process which is something you would not experience when using ThreadPool because it does not have the same need for serialization.

Example showing invocation of __new__ as part of unpickling:
>>> class Foo(object):
...     def __new__(cls):
...         print("New")
...         return object.__new__(cls)
>>> import pickle
>>> f = Foo()
>>> pf = pickle.dumps(f, protocol=2)
>>> pickle.loads(pf)                  # unpickling triggers __new__
<__main__.Foo object at 0x1084a06d0>

Having discovered this phenomenon, is this causing a problem for you somewhere in code?  (Your example code on github was helpful, thank you, but it didn't merely demonstrated the behavior and didn't show where this was causing you pain.)
Date User Action Args
2017-04-07 20:49:12davinsetrecipients: + davin, Charles McEachern
2017-04-07 20:49:12davinsetmessageid: <>
2017-04-07 20:49:12davinlinkissue30018 messages
2017-04-07 20:49:12davincreate