程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python remote interactive debug

編輯:Python

brief introduction

In daily development , There will be some pain points , Conventional methods cannot debug, Such as :

  • The production environment is not completely consistent with the test environment , In the test environment , Some scenes cannot be reproduced

  • The program log is not detailed enough

  • You need to quickly define problems through interactive debugging , And you need to try to change the value of the variable to reproduce

Obviously , It's not a special moment , No need to consider remote debug In the form of .

long-range Debug

PyCharm Provide remote debug, But it's heavier , Here we go through remote-pdb(https://github.com/ionelmc/python-remote-pdb) To achieve remote debug.

First of all, let's get to know remote-pdb, Everyday we develop py when , Will use pdb debug , but pdb It does not provide the function of remote debugging , The developer is based on pdb Developed pdbx,pdbx Can be pdb Debugging information passed telnet or nc Command delivery , So as to achieve the effect of remote debugging ,remote-pdb stay pdbx above , Another layer of encapsulation , It will be more convenient to use .

install remote-pdb

pip install remote-pdb

We go through Python Write a Fibonacci sequence code :

from remote_pdb import RemotePdb
rpdb = RemotePdb('127.0.0.1', 6666)
def fib(n):
    a,b = 1,1
    for i in range(n-1):
        a,b = b,a+b
    #  The breakpoint
    rpdb.set_trace()
    return a
 
print (fib(10))

In the above code , Introduced remote_pdb Medium RemotePdb Class and instantiate rpdb, We can follow up by telnet or nc Command to link RemotePdb Provided TCP service .

Here we choose telnet, If you are windows System , You need to open before telnet service , stay windows In the set , find 【 Start or close windows function 】, And find it in there telnet Relevant stuff , Just turn it on .


Run the program with the breakpoint , And then through 【telnet 127.0.0.1 6666】 De link , You will enter the attribute pdb Interactive environment , Then you can go through pdb To query the information in the program , Here's the picture :

ending

Very simple technique , Last one PDB Command diagram for .


I'm two liang , See you next article .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved