Execute in a multiprocessing child dynamic code loaded by the parent process
Martin Di Paola
martinp.dipaola at gmail.com
Mon Mar 7 08:32:44 EST 2022
I understand that yes, pickle.loads() imports any necessary module but
only if they can be find in sys.path (like in any "import" statement).
Dynamic code loaded from a plugin (which we presume it is *not* in
sys.path) will not be loaded.
Quick check. Run in one console the following:
import multiprocessing
import multiprocessing.reduction
import pickle
pickle.dumps(multiprocessing.reduction.ForkingPickler)
<copy the output>
In a separated Python console run the following:
import pickle
import sys
'multiprocessing' in sys.modules
False
pickle.loads(<paste the dump here>)
'multiprocessing' in sys.modules
True
So the last check proves that pickle.loads imports any necessary module.
Martin.
On Mon, Mar 07, 2022 at 08:28:15AM +0000, Barry wrote:
>
>
>> On 7 Mar 2022, at 02:33, Martin Di Paola <martinp.dipaola at gmail.com> wrote:
>>
>> Yes but I think that unpickle (pickle.loads()) does that plus
>> importing any module needed
>
>Are you sure that unpickle will import code? I thought it did not do that.
>
>Barry
More information about the Python-list
mailing list