pyodide/manager/manager.js - Pyodide Manager
Location: src/pyodide/manager/manager.js
This file contains the PyodideManager class, which is the core component for managing the Pyodide execution environment. It handles the creation and communication with the Pyodide web worker.
Class: PyodideManager
constructor(packages, micropipPackages, filesToLoad, workerPath)
- Description: Creates a new
PyodideManagerinstance. It performs strict validation on all parameters and initializes the web worker. - Parameters:
packages(Array): A list of standard Python packages to install. micropipPackages(Array): A list of packages to install via micropip.filesToLoad(ArrayworkerPath(string): The path to the bundled worker script (worker-dist.js).
- Throws:
Errorif any parameter is invalid.
executeAsync(filename, code, namespace)
- Description: Executes Python code asynchronously and returns a promise that resolves with the result. This is the primary method for running code.
- Parameters:
filename(string): A name for the execution, used for tracking.code(string): The Python code to execute.namespace(Object, optional): An object to use as the global namespace.
- Returns: A
Promisethat resolves to anExecutionResultobject.
executeFile(filename, code, namespace)
- Description: Executes Python code in a "fire-and-forget" manner, without returning a result.
- Parameters: Same as
executeAsync.
fs(operation, params)
- Description: Provides an interface to the virtual filesystem within the Pyodide worker.
operation(string): The filesystem operation to perform (e.g.,'writeFile','readFile').params(Object): Parameters for the operation.
Input Handling
provideInput(input): Provides a string of input to the waiting Python process.queueInput(input): Adds a string to the input queue for futureinput()calls.setInputCallback(callback): Sets a callback function to be invoked when Python requests input.isWaitingForInput(): Returnstrueif the Python environment is waiting for input.getCurrentPrompt(): Returns the prompt message from the currentinput()call.
destroy()
- Description: Terminates the web worker and cleans up resources, including revoking the blob URL, to prevent memory leaks.
Properties
isReady(boolean):trueif the manager is initialized and ready for execution.executionHistory(Arrayworker(Worker): TheWorkerinstance.packages(Array): The list of packages to be loaded. micropipPackages(Array): The list of packages to be loaded via micropip.filesToLoad(Array