Skip to main content

A proof-of-concept snapshot, transmission and restoring python runtime

Project description

build

pyteleport

A proof-of-concept serialization, transmission and restoring python runtime.

Install

pip install pyteleport

Example

from socket import gethostname
from os import getpid
def log(*args):
    print(f"[{gethostname()}/{getpid()}]", *args)

from pyteleport import bash_teleport

log("hi")
bash_teleport("ssh", "cartesius", "conda activate py39;")
log("bye")

output:

[stealth/4258] hi
[int1.bullx/17980] bye

Note that the two outputs were produced by different processes on different machines! This is what bash_teleport does: it transmits the runtime from one python process to another.

Also works from within a stack:

def a():
    def b():
        def c():
            result = "hello"
            bash_teleport(...)
            return result + " world"
        return len(c()) + float("3.5")
    return 5 * (3 + b())
assert a() == 87.5

How it works

  • You invoke teleport in your python script.
  • pyteleport collects the runtime state: globals, locals, stack.
  • pyteleport dumps the runtime into a specially designed "morph" bytecode which resumes from where teleport was invoked.
  • The bytecode is transmitted to the target environment and passed to a python interpreter there.
  • The remote python runs the bytecode which restores the runtime state. The python program casually resumes from where it was interrupted.
  • The local python runtime is terminated and simply pipes stdio from the target environment.

Known limitations

This is a proof of concept. The package assumes cPython v3.8 or 3.9.

What is working / not working:

  • MWE: snapshot, serialize, transmit, restore
  • serialize generators
  • threads (currently ignored)
  • for, try, with (never tested)
  • async (never tested but likely needs minimal changes)
  • yield from (never tested)
  • non-python stack (won't fix)
  • forking to remote (non-destructive teleport, needs investigating)
  • back-teleport (needs API development)
  • nested teleport (needs minimal changes)
  • cross-fork communications (need API development)
  • REPL integration (needs investigating)
  • more python versions (maybe)
  • cross-version (needs investigating)

The list is not final.

History

  • 11 July 2021 20:46 CEST a python runtime was first teleported to another machine

License

LICENSE.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyteleport-0.1.tar.gz (13.3 kB view details)

Uploaded Source

File details

Details for the file pyteleport-0.1.tar.gz.

File metadata

  • Download URL: pyteleport-0.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for pyteleport-0.1.tar.gz
Algorithm Hash digest
SHA256 1298987718a2cb21bc7c58a6339119c6a9bbb1144b9c286278f2873fa4edaa7d
MD5 0c7a5065b62c7633d77280792af9b413
BLAKE2b-256 2767bc6792efefcec2fd90178924991627c6fb3cc947f1d9a95ccede72928550

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page