Lynxer

Documentation

multiprocessing

Run shell commands in parallel.

Backend: native + pure — stdlib/multiprocessing.so (stdlib/multiprocessing.cpp) runs the commands; stdlib/multiprocessing.lynx reads the results back into Lynxer lists. Import: import("multiprocessing") → global.multiprocessing.*

Commands run in worker threads, each spawning its own shell subprocess. Results are always returned in input order, whatever order they finish in. A command's stderr is captured into its output, and a command that outlives the timeout (LYNXER_MP_TIMEOUT seconds, default 300, 0 for no limit) is killed and reports exit code 124. The timeout kills the complete process group, not only the shell wrapper. Captured stdout and stderr are concatenated in their original pipe order.

FunctionSignatureReturns
workerCount() -> intNumber of online CPUs, at least 1
runParallel(list commands) -> listCaptured stdout per command
runParallelSilent(list commands) -> listExit code per command
runParallelProcess(list commands) -> listAlias of runParallel
mapShell(str template, list items) -> listReplaces the first {} in template with each item, runs in parallel, returns stdout per item
threadMap(str template, list items) -> listAlias of mapShell
runParallelHandle(list commands) -> intLow-level result handle for output/code queries

resultCount(handle), resultAt(handle, index), and codeAt(handle, index) read one handle. release(handle) frees it and returns true; subsequent queries return 0, "", or -1. The list-returning convenience functions release their handles automatically.

Results are collected through a native handle registry rather than a joined string, because command output can contain any character. The wrappers release each handle automatically. Native callers that use the handle operations directly must call release(handle); result queries on released or unknown handles return their invalid-handle sentinels.

Example

global setup(){ import("multiprocessing"); }

global main(){
    list commands = listPush(listPush(listRepeat("", 0), "printf a"), "printf b");
    println(global.multiprocessing.runParallel(commands));

    list items = listPush(listPush(listRepeat("", 0), "x"), "y");
    println(global.multiprocessing.mapShell("printf {}", items));
}

See also