简体   繁体   English

使用PDB调试python拥抱API

[英]Debugging python hug api with pdb

I'm trying to debug a python hug API with pdb . 我正在尝试使用pdb调试python hug API。

The regular hug api is started with: hug -f api.py 常规的拥抱api以以下内容开头: hug -f api.py

You can start pdb from the command line via python interpreter using: 您可以使用以下命令通过python解释器从命令行启动pdb:

python -m pdb api.py

Where api.py contains hug routes, directives etc. api.py however needs to be run with hug -f api.py which doesn't accept -m pdb . 其中api.py包含拥抱路线,指令等。但是api.py需要与不接受-m pdb hug -f api.py运行。

eg: hug -m pdb -f api.py doesn't work. 例如: hug -m pdb -f api.py不起作用。

I also tried creating a debug.py file and import api.py into it with debugging started. 我还尝试创建debug.py文件,并在调试开始时将api.py导入其中。 But it doesn't register the routes in api.py . 但是它没有在api.py注册路由。

import pdb
from api import *

@hug.startup()
def startup(args):
    """Starts api and debugging"""
    pdb.set_trace()

The hug server starts ok, but without any routes defined in api.py . 拥抱服务器启动正常,但没有在api.py定义任何路由。

At the moment I'm resorting to having to put pdb.set_trace() directly into one of the routes in api.py . 目前我诉诸不必把pdb.set_trace()直接进入的途径之一api.py This works but is tedious. 这可行,但很乏味。 Ideally there should be a way to start api.py with hug and pdb debugging and set breakpoints dynamically without restarting hug . 理想情况下,应该有一种方法可以通过hugpdb调试来启动api.py并动态设置断点而无需重新启动hug

This happens because the auto re-loader can not handle with debugger. 发生这种情况是因为自动重新加载程序无法使用调试器进行处理。

Use --manual_reload option when start app. 启动应用程序时使用--manual_reload选项。

More about this issue here 更多关于这个问题在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM