Spawn multiprocessing.Process under different python executable with own path -
i have 2 versions of python (these 2 conda environments)
/path/to/bin-1/python /path/to/bin-2/python
from 1 version of python want launch function runs in other version using multiprocessing.process
object. turns out doable using set_executable
method:
ctx = multiprocess.get_context('spawn') ctx.set_executable('/path/to/bin-2/python')
and indeed can see in fact launch using executable:
def f(q): import sys q.put(sys.executable) if __name__ == '__main__': import multiprocessing ctx = multiprocessing.get_context('spawn') ctx.set_executable('/path/to/bin-2/python') q = ctx.queue() proc = ctx.process(target=f, args=(q,)) proc.start() print(q.get()) $ python foo.py /path/to/bin-2/python
however path wrong
however when same thing sys.path
rather sys.executable
find sys.path hosting python process printed out instead, rather sys.path find running /path/to/bin-2/python -c "import sys; print(sys.path)"
directly.
i'm used sort of thing if use fork. have expected 'spawn'
act same though had entered python interpreter shell.
question
is possible use multiprocessing library run functions , use queues python executable environment have had had started shell?
more broadly, how sys.path populated , different between using multiprocessing in way , launching interpreter directly?
Comments
Post a Comment