execnet: Distributed Python Deployment and Communication
execnet is a Python library that provides carefully tested means to ad-hoc interact with Python interpreters across different versions, platforms, and network barriers. It offers a minimal and fast API for distributing tasks to local or remote processes, writing hybrid multi-process applications, and administering multiple hosts. The project is currently in maintenance-only mode, with a focus on bug fixes, and is not recommended for new projects. The current stable version is 2.1.2, with releases driven by bug fixes and Python version compatibility updates.
Warnings
- deprecated execnet is in maintenance-only mode and should not be used for new projects. Modern Python's capabilities for inter-interpreter communication often make `execnet` unnecessary. It is primarily maintained because it serves as the backend for `pytest-xdist`.
- breaking Version 2.0.0 dropped support for Python versions older than 3.7. Ensure your environment meets the minimum Python requirement of >=3.8.
- breaking Version 1.5.0 removed support for Python 2.6 and 3.3. Earlier versions of Python 3.x (e.g., 3.3) are no longer supported.
- gotcha When using `python=` in a gateway specification, especially with `popen` or `ssh` gateways, pathnames containing spaces can lead to potential regressions or unexpected behavior due to the internal use of `shlex.split`.
- gotcha The `execnet.dumps` and `execnet.loads` API for cross-interpreter compatible serialization of Python builtin types was introduced in version 1.1. Using serialization mechanisms across different `execnet` versions or without these explicit functions might lead to incompatibility issues.
Install
-
pip install execnet
Imports
- makegateway
import execnet gateway = execnet.makegateway()
- remote_exec
channel = gateway.remote_exec(source_code)
Quickstart
import execnet
gateway = execnet.makegateway()
channel = gateway.remote_exec("channel.send('hello from remote!')")
message = channel.receive()
print(f"Received from remote: {message}")
channel.send('hello from local!')
channel.waitclose()
gateway.exit()