Hi, is there a way to debug inside visual studio t...
# ask-for-help
s
Hi, is there a way to debug inside visual studio the python code of service.py? is there a tutorial for debugging each line of code?
c
Not sure about visual studio but I know @Eric Riddoch is building a plugin for VSCode! #vscode-hackathon
s
Sorry it was VSCode, my mistake!. But is there a way to make it run with command line "bentoml serve ." and then debug the service.py ?
e
Hey! Yes this seems like a separate question from "is there a VS Code extension" (and there soon will be btw!) ----- I think this question could be rephrased as "is there a way to set breakpoints to step debug the service.py in VS Code?" I personally haven't done this, but I bet there is. I did this for FastAPI once. Here's a
launch.json
for FastAPI. I bet you could modify this to use the
bentoml serve
command.
Copy code
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: <https://go.microsoft.com/fwlink/?linkid=830387>
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: FastAPI",
            "type": "python",
            "request": "launch",
            "module": "uvicorn",
            "env": {
                "db_username": "postgres",
                "db_password": "secret",
                "host_server": "localhost",
                "database_name": "fastapi",
                "ssl_mode": "prefer",
                "db_server_port": "5432"
            },
            "args": [
                "main:app",
                "--reload",
                "--port",
                "8000"
            ]
        }
    ]
}
I got the file from here. If you get a
launch.json
working. Would you mind sharing it here? Me and my team will probably need this too in a week or two!
Here's an attempt to get it to work:
Copy code
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: BentoML",
      "type": "python",
      "request": "launch",
      "module": "bentoml",
      "env": {
        "some": "env var"
      },
      "args": [
        "serve",
        "--port",
        "3000"
      ]
    }
  ]
}
s
I'll review and let you know, many thanks!
It's not working yet, but is there a way to use the bentoml.Server or bentoml.serve by importing the libraries and doing a call from let's say , if name=="__main__": ???
In the same file service.py, i've added the following, it seems you can debug it, though it same some errors on some cython files because of the debugger:
Copy code
if __name__=="__main__":
    bento_id = "."
    # o si tienes un objeto Bento
# Crear una instancia del servidor HTTP en modo desarrollo con recarga automática.
    http_server = HTTPServer(
        bento=bento_id,
        reload=True,  # Habilitar recarga automática en desarrollo.
        production=False,  # Indicar que estamos en modo de desarrollo.
        #host="127.0.0.1",  # El host del servidor.
        #port=5000,  # El puerto en el que el servidor debe escuchar.
        backlog=100,
        #working_dir="/data/projects/TranscripcionBM"
    )
    # Iniciar el servidor.
    with http_server.start(blocking=True) as client:
        print(f"Servidor HTTP corriendo en modo desarrollo en http://{http_server.host}:{http_server.port}")
e
Oh this works? If so, nice!! Also, I learned that you can do “bentoml serve —development”. I’m not sure but if you add that flag, the launch.json might work!
s
it works with this, thanks for the help and it's better than my previous attempt:
Copy code
{
    // Use IntelliSense para saber los atributos posibles.
    // Mantenga el puntero para ver las descripciones de los existentes atributos.
    // Para más información, visite: <https://go.microsoft.com/fwlink/?linkid=830387>
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Depurador de Python: Archivo actual",
            "type": "debugpy",
            "request": "launch",
            "module": "bentoml",
            "args":[
                "serve",
                ".",
                "--development"
            ],
            "console": "integratedTerminal",
            "justMyCode": false,
            "cwd":"${workspaceFolder}/TranscripcionBM",
            "env": {
                "PYDEVD_DISABLE_FILE_VALIDATION": "1"
            }
        }
    ]
}
e
Heeeey! This is great! I’ll save this. Was there a particular reason you used “debugpy” instead of “module” for the launch type? Also, does the “justMyCode” option work the way you expect? Or did you run into problems when you set it to “true”?
s
debugpy is the one that is VSCode suggesting to change, and not use anymore python. With justmy code, is to see the errors inside de code of bentoml, it's working fine so far now.
🙌 1