modal.runner

modal.runner.deploy_stub

def deploy_stub(self, *args, **kwargs):
    # .__call__ is special - it's being looked up on the class instead of the instance when calling something,
    # so setting the magic method from the constructor is not possible
    # https://stackoverflow.com/questions/22390532/object-is-not-callable-after-adding-call-method-to-instance
    # so we need to use an explicit wrapper function here

Deploy an app and export its objects persistently.

Typically, using the command-line tool modal deploy <module or script> should be used, instead of this method.

Usage:

if __name__ == "__main__":
    deploy_stub(stub)

Deployment has two primary purposes:

  • Persists all of the objects in the app, allowing them to live past the current app run. For schedules this enables headless “cron”-like functionality where scheduled functions continue to be invoked after the client has disconnected.
  • Allows for certain kinds of these objects, deployment objects, to be referred to and used by other apps.

modal.runner.interactive_shell

def interactive_shell(self, *args, **kwargs):
    # .__call__ is special - it's being looked up on the class instead of the instance when calling something,
    # so setting the magic method from the constructor is not possible
    # https://stackoverflow.com/questions/22390532/object-is-not-callable-after-adding-call-method-to-instance
    # so we need to use an explicit wrapper function here

Run an interactive shell (like bash) within the image for this app.

This is useful for online debugging and interactive exploration of the contents of this image. If cmd is optionally provided, it will be run instead of the default shell inside this image.

Example

import modal

stub = modal.Stub(image=modal.Image.debian_slim().apt_install("vim"))

You can now run this using

modal shell script.py --cmd /bin/bash

modal.runner.run_stub

def run_stub(self, *args, **kwargs):
    # .__call__ is special - it's being looked up on the class instead of the instance when calling something,
    # so setting the magic method from the constructor is not possible
    # https://stackoverflow.com/questions/22390532/object-is-not-callable-after-adding-call-method-to-instance
    # so we need to use an explicit wrapper function here

modal.runner.serve_update

def serve_update(self, *args, **kwargs):
    # .__call__ is special - it's being looked up on the class instead of the instance when calling something,
    # so setting the magic method from the constructor is not possible
    # https://stackoverflow.com/questions/22390532/object-is-not-callable-after-adding-call-method-to-instance
    # so we need to use an explicit wrapper function here