Python Glossary Русский

all Python 3multiprocessingfunction

multiprocessing.set_executable()

start methods

Sets the path of the Python interpreter used to launch child processes under spawn. The default is sys.executable.

Syntax

multiprocessing.set_executable(executable)

It is mostly for embedding: when sys.executable points at a host program instead of python, or when Windows needs pythonw.exe without a console. The path must lead to an interpreter of the same version with the same packages, or the child fails while unpickling. Under fork no interpreter is started, so the setting has no effect. Since 3.11 it accepts a path-like object.

Examples

import multiprocessing as mp
import sys
def which(q):
    q.put(sys.executable)
if __name__ == '__main__':
    ctx = mp.get_context('spawn')
    ctx.set_executable(sys.executable)
    q = ctx.Queue()
    p = ctx.Process(target=which, args=(q,))
    p.start()
    print(q.get(timeout=10) == sys.executable)  # → True
    p.join()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy