Module executor
This script launches a server inside a specified conda environment. It listens on a dynamically assigned local port for incoming execution commands sent via a multiprocessing connection.
Clients can send instructions to: - Dynamically import a Python module from a specified path and execute a function - Run a Python script via runpy.run_path() - Receive the result or any errors from the execution
Designed to be run within isolated environments for sandboxed execution of Python code modules.
Functions:
| Name | Description |
|---|---|
sendMessage |
Thread-safe sending of messages. |
handleExecutionError |
Common error handling for any execution type. |
executeFunction |
Import a module and execute one of its functions. |
runScript |
Run a Python script via runpy.run_path(), simulating 'python script.py args...'. |
executionWorker |
Worker function handling both 'execute' and 'run' actions. |
launchListener |
Launches a listener on a random available port on localhost. |
sendMessage(lock, connection, message)
handleExecutionError(lock, connection, e)
Common error handling for any execution type.
Source code in wetlands/_internal/module_executor.py
executeFunction(message)
Import a module and execute one of its functions.
Source code in wetlands/_internal/module_executor.py
runScript(message)
Run a Python script via runpy.run_path(), simulating 'python script.py args...'.
Source code in wetlands/_internal/module_executor.py
executionWorker(lock, connection, message)
Worker function handling both 'execute' and 'run' actions.
Source code in wetlands/_internal/module_executor.py
launchListener()
Launches a listener on a random available port on localhost. Waits for client connections and handles 'execute', 'run', or 'exit' messages.