Debugging¶
PyTauri Runtime¶
You can use the following APIs to inspect the current pytauri runtime configuration:
- pytauri.IS_DEV: Indicates if running in tauri devmode
- pytauri.VERSION: The current version of tauri
- pytauri.webview_version: The current version of the webview
Debug in VSCode¶
Python¶
Dependencies¶
First, install the Python Debugger extension in VSCode.
Then, add debugpy as your python development dependency and install it:
Configure launch.json¶
Refer to https://code.visualstudio.com/docs/python/debugging#_initialize-configurations.
Add the following configuration:
{
    "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:
- 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:
{
    "lldb.rpcServer": {
        "host": "localhost",
        "port": 9552,
        "token": "secret",
    },
}
Start Debugging¶
Add the following code to your app:
"""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:
When you see the "Waiting for debugger to attach..." output, you can attach the Python Debugger to your app to start debugging Python code:
The CodeLLDB debugger will automatically attach to your app; you do not need to start it manually.