Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Crane04/esem/llms.txt
Use this file to discover all available pages before exploring further.
ensureWorker() is a lower-level utility that guarantees the Python worker subprocess is running and ready to accept requests. python() calls it automatically before returning any module proxy, so most application code never needs to call it directly. The main use-case for calling it explicitly is pre-warming — starting the worker at server startup so the first python() call has no cold-start latency.
Signature
Parameters
ensureWorker() takes no parameters.
What it does
- If the worker is already running, returns the existing ready
Promiseimmediately — there is no extra spawn attempt and no race condition. - If no worker is running, spawns the bundled
worker.pyscript usingpython3(or the binary specified by$ESEM_PYTHON) as a child process withstdiofully piped. The worker’s current working directory is set toprocess.cwd()so that relative module imports resolve correctly. - Resolves when the worker sends
{"type": "ready"}on its stdout, signalling that it has finished initialising and is ready to process requests.
Pre-warming the worker
The most common reason to callensureWorker() directly is to eliminate the cold-start delay that would otherwise occur on the first python() call:
python() calls ensureWorker() automatically before returning the module proxy. You never need to call ensureWorker() before python() — doing so is harmless and simply returns the already-resolved ready promise.