Skip to content

Debugging

PyTauri Runtime

You can use the following APIs to inspect the current pytauri runtime configuration:

Debug in VSCode

Python

Refer to https://code.visualstudio.com/docs/python/debugging#_debugging-by-attaching-over-a-network-connection.

Dependencies

First, install the Python Debugger extension in VSCode.

Then, add debugpy as your python development dependency and install it:

src-tauri/pyproject.toml
# ...

[dependency-groups]
dev = [
    # ...
    "debugpy == 1.*"
]

Configure launch.json

Refer to https://code.visualstudio.com/docs/python/debugging#_initialize-configurations.

Add the following configuration:

.vscode/launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Remote Attach",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
        },
    ]
}

Rust

Refer to https://github.com/vadimcn/codelldb/blob/v1.11.5/MANUAL.md#attaching-to-a-running-process.

Dependencies

First, install the CodeLLDB extension in VSCode.

Then, add codelldb as your python development dependency and install it:

src-tauri/pyproject.toml
# ...

[dependency-groups]
dev = [
    # ...
    "codelldb == 0.1.*"  # (1)!
]
  1. This is the version at the time of writing this tutorial. There may be a newer version of pytauri available when you use it.

Configure settings.json

Refer to https://github.com/vadimcn/codelldb/blob/v1.11.5/MANUAL.md#rpc-server.

Add the following configuration:

.vscode/settings.json
{
    "lldb.rpcServer": {
        "host": "localhost",
        "port": 9552,
        "token": "secret",
    },
}

Start Debugging

Add the following code to your app:

src-tauri/python/tauri_app/__main__.py
"""The main entry point for the Tauri app."""

from os import environ

if environ.get("PYTAURI_DEBUG_PY") == "1":
    import debugpy  # pyright: ignore[reportMissingTypeStubs]

    debugpy.listen(5678)
    print("Waiting for debugger to attach...")
    # debugpy.wait_for_client()


if environ.get("PYTAURI_DEBUG_RS") == "1":
    import codelldb

    codelldb.debug(host="localhost", port=9552, token="secret")

# -- main ---------------------------------------------------------------------

import sys
from multiprocessing import freeze_support

from tauri_app import main

# - If you don't use `multiprocessing`, you can remove this line.
# - If you do use `multiprocessing` but without this line,
#   you will get endless spawn loop of your application process.
#   See: <https://pyinstaller.org/en/v6.11.1/common-issues-and-pitfalls.html#multi-processing>.
freeze_support()

sys.exit(main())

Start your app:

$env:PYTAURI_DEBUG_PY = "1"
$env:PYTAURI_DEBUG_RS = "1"
pnpm tauri dev
export PYTAURI_DEBUG_PY="1"
export PYTAURI_DEBUG_RS="1"
pnpm tauri dev

When you see the "Waiting for debugger to attach..." output, you can attach the Python Debugger to your app to start debugging Python code:

debugging

The CodeLLDB debugger will automatically attach to your app; you do not need to start it manually.