04-04-2018 11:44 PM - edited 03-01-2019 04:08 AM
Hi,
Anyone know how to use python pdb debugger within NSO service code for debugging the code?
Regards,
Shameer
04-05-2018 11:48 AM
Hi Shameer
You cannot easily use pdb with service code, because it runs as a service. You can potentially use the pdb module to enhance your logging, but it is probably not what you want.
What you want is a debugger that can be attached remotely. I know that pycharm has a debugger like that, but I have never tried using it with nso. This thread https://communities.cisco.com/message/249111#249111 talks a little bit about it and it seems that others have had success with it.
Best Regards,
Viktor
10-09-2018 12:37 PM
Well, while Viktor said - "you cannot easily use pdb with service code" - doesn't mean it's impossible, and frankly it's really not that hard at all. The functionality has been there since version NSO 4.2 when we began supporting Python for service development.
Try this in ncs_cli -J (configure mode):
% show python-vm | details
auto-start true;
auto-restart true;
run-in-terminal {
disabled;
terminal-command "xterm -title ncs-python-vm -e";
}
logging {
log-file-prefix ./logs/ncs-python-vm;
level level-info;
}
You can configure NSO to run each Python VM in a terminal! If you're okay with xterm the only thing you need to configure is:
% set python-vm run-in-terminal enabled
So, now NSO will execute the startup script in an xterm terminal and you may use
import pdb
pdb.set_trace()
in your service-callback to set a breakpoint and invoke pdb.
Please note that this will make all Python VMs controlled by NSO run in an xterm so a couple of windows may pop up depending on your configuration. If you're on a Mac you can use the xQuartz.app as an X11 server.
Good luck!
/Tomas
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide