Functionality questions #2
-
Thanks for making this project. A non-interactive python debugger is exactly what I'm looking for. I'd like to use your project to support the Python probe for Source++. I've been able to successfully implement some portions of the functionality, but I'm having some trouble understanding some Python debugging relating things. I think some of this trouble might be alleviated with new functionality for nopdb and I'm more than willing to implement that functionality. My background is with JVM languages so I'm just looking for a bit of guidance on how things work the Python way. Breakpoint doesn't hit on Flask appI don't think this issue is a nopdb issue as I'm unable to hit the breakpoint using Here is some code that shows a breakpoint that's never hit: import os
from flask import Flask
from nopdb import nopdb
app = Flask(__name__)
@app.route('/')
def hello():
provider = str(os.environ.get('PROVIDER', 'world'))
return 'Hello ' + provider + '!'
if __name__ == '__main__':
with nopdb.breakpoint(file="FlaskTest.py", line=12) as bp:
bp.exec("print(\"provider: \" + provider)")
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port) Ability to add breakpoints without calling code via context managerThis might be related to the issue above, but how do you add breakpoints to code that you don't want to call via the context manager? As in, code that is already running or that will run by itself sometime in the future? I have a small example here where I want to set a breakpoint before a function is called in the future via a delay. Can nopdb address this type of scenario? Code which shows a breakpoint that's never hit: import threading
from nopdb import nopdb
def fun():
x = 5
y = x
if __name__ == '__main__':
start_time = threading.Timer(10, fun)
start_time.start()
# I'd like to set the breakpoint ahead of time and just output x once it's hit
with nopdb.breakpoint(file="SeparateThread.py", line=8) as bp:
bp.exec("print(\"x: \" + str(x))") Does cpdb make sense to extend?This might be a bit off-topic, but while looking into Python debuggers I ran across https://pypi.org/project/CPdb/. Does this project make sense to extend for nopdb? The reason I ask is because of the claim cpdb makes about "long-running" applications running better with it. I would like to use nopdb in "long-running" applications so I'm curious if it makes sense to integrate the technologies. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thanks for your questions! Let me answer the second question first, which is actually about two things: using NoPdb without a context manager, and threads. Yes, you can use NoPdb without a context manager: you just need to call the import nopdb
def fun():
x = 5
y = x
if __name__ == '__main__':
dbg = nopdb.get_nopdb() # Get the default NoPdb object for this thread
dbg.breakpoint(file="myscript.py", line=6).exec("print(\"x: \" + str(x))") # nopdb.breakpoint() would also work here
dbg.start() # Start debugging
fun()
dbg.stop() About threads: A debugger is normally attached to only one thread (the one that started it), so that explains why your breakpoint is not getting hit. I don't know if it's even possible to attach it to a different thread that is already running. What NoPdb does is call So while multi-thread support should be possible to implement (and I agree it would be useful), I think it would be complicated because of thread safety (maybe not that much for breakpoints, but definitely for the I'm not sure about the Flask question, but I guess threading will be one issue. Finally, regarding CPdb, I haven't heard about it. Which of its functionalities do you think it could be interesting to have here? |
Beta Was this translation helpful? Give feedback.
Thanks for your questions!
Let me answer the second question first, which is actually about two things: using NoPdb without a context manager, and threads. Yes, you can use NoPdb without a context manager: you just need to call the
start()
method of aNoPdb
object, e.g.:About threads: A debugger is normally attached to only one thread (the one that started it…