I need to execute a python function with python3.8 and I'm running my main program on python3.9.
My main program looks like this:
import multiprocessing as mp
def run(function, executable):
mp.set_start_method("spawn", force=True)
mp.set_executable(executable)
p = mp.Process(target=function)
p.start()
if __name__ == "__main__":
from module import foo
run(
function=foo.bar,
executable="/bin/python3.8",
)
The bar function from the foo module is like this:
import pathlib
def bar():
"""Do some python3.8 here"""
When importing packages in the code executed by python3.8 (checked by printing sys.executable), it seems to import the packages from python3.9. In my case I have this issue with the pathlib package, but the same happened with numpy:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/usr/lib/python3.8/multiprocessing/spawn.py", line 126, in _main
self = reduction.pickle.load(from_parent)
File "/gitrepos/mp-issue/module/foo.py", line 1, in <module>
import pathlib
File "/usr/lib/python3.9/pathlib.py", line 13, in <module>
from urllib.parse import quote_from_bytes as urlquote_from_bytes
File "/usr/lib/python3.9/urllib/parse.py", line 147, in <module>
class _NetlocResultMixinBase(object):
File "/usr/lib/python3.9/urllib/parse.py", line 183, in _NetlocResultMixinBase
__class_getitem__ = classmethod(types.GenericAlias)
AttributeError: module 'types' has no attribute 'GenericAlias'
I guess that I will have this issue with all the 3.9 packages not compatible with 3.8. I tried moving the import in the bar function but the error still happened.
Am I misusing multiprocessing, or should I do this in an other way ?