Author davin
Recipients Charles McEachern, davin
Date 2017-04-07.20:49:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1491598152.58.0.538958129278.issue30018@psf.upfronthosting.co.za>
In-reply-to
Content
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()
New
>>> pf = pickle.dumps(f, protocol=2)
>>> pickle.loads(pf)                  # unpickling triggers __new__
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.)
History
Date User Action Args
2017-04-07 20:49:12davinsetrecipients: + davin, Charles McEachern
2017-04-07 20:49:12davinsetmessageid: <1491598152.58.0.538958129278.issue30018@psf.upfronthosting.co.za>
2017-04-07 20:49:12davinlinkissue30018 messages
2017-04-07 20:49:12davincreate