Execute in a multiprocessing child dynamic code loaded by the parent process

Martin Di Paola martinp.dipaola at gmail.com
Sun Mar 6 21:30:17 EST 2022


>>
>> Yeup, that would be my first choice but the catch is that "sayhi" may
>> not be a function of the given module. It could be a static method of
>> some class or any other callable.
>
>Ah, fair. Are you able to define it by a "path", where each step in
>the path is a getattr() call?

Yes but I think that unpickle (pickle.loads()) does that plus
importing any module needed
in the path which it is handy because I can preload the plugins
(modules) before the unpickle but the path may contain others
more-standard modules as well.

Something like "myplugin.re.match". unpickle should import 're' module
automatically will it is loading the function "match".

>Fair. I guess, then, that the best thing to do is to preload the
>modules, then unpickle. So, basically what you already have, but with
>more caveats.

Yes, this will not be transparent for the user, just trying to minimize
the changes needed.

And it will require some documentation for those caveats. And tests.

Thanks for the brainstorming!
Martin.


More information about the Python-list mailing list