Skip to contents

Returns a launcher that spawns Python processes running pymizu, the Python binding of the same shared-memory core: python -m pymizu.child for the channel peer of mizu_channel(), and python -m pymizu.worker for the pool workers of mizu_pool() and mizu_spawn_workers(). It is the counterpart of pymizu's r_launcher(), which spawns R processes from a Python host.

Usage

mizu_py_launcher(python = NULL, stdout = "", stderr = "")

Arguments

python

path to the Python interpreter. The default looks up python3 on the PATH.

stdout, stderr

forwarded to system2() for the spawned process, as in mizu_launcher().

Value

A function(token, slot). mizu_channel() calls it with token alone to spawn the peer. mizu_pool() and mizu_spawn_workers() call it with both arguments to spawn the worker for slot.

Details

The first worker to join records the workers' language in the pool, so the launcher carries no language attribute. A pool of Python workers takes mizu_call() specifications through mizu_submit_call(), and a plain mizu_submit() fails immediately with an error naming mizu_submit_call(). A launcher that spawns the wrong language fails at join, not at the first task.

The interpreter is probed for pymizu when the launcher is created, so a missing interpreter or package errors here, before any channel or pool is created. The payload rules for a non-R channel peer apply: only vectors and strings cross (see mizu_send()).

Examples

if (FALSE) { # interactive()
ch <- mizu_channel(
  r"(
import pymizu
while True:
    x = ch.recv(30)
    if pymizu.is_sentinel(x):
        break
    ch.send(x * 2)
)",
  launcher = mizu_py_launcher()
)
mizu_send(ch, c(1.5, 2.5, 3.5))
mizu_recv(ch, timeout = 5)
mizu_close(ch)

p <- mizu_pool(2, launcher = mizu_py_launcher())
t <- mizu_submit_call(p, mizu_call("numpy.mean", runif(100)))
mizu_collect(t)
mizu_pool_stop(p)
}