My application is written in C/C++ and Python is embed to extend some
functions (several .py files are invoked). But I am confused how to
debug these embed Python? Can I use 'print-debuging'? and where can I
capture the output string?
Or Python can support 'break' debug for such scenario?
Thanks.
#############
from socket import *
udpSock = socket(AF_INET,SOCK_DGRAM)
def log(s):
udpSock.sendto(s, ('127.0.0.1', 514))
log('hello')
You should be able to use the python debugger (pdb) by manually putting
import pdb; pdb.set_trace()
on a place that is of interest to you. Then if your program is started
inside a shell, you should be able to step-debug it.
Additinoally, there is the very flexible & powerful logging-module that
you can use to write logfiles. This is better than simple
print-statements, as you can keep the logging statements around and just
turn them on or off on demand.
Additionally, printing might not work reliably in cases where the
stdout/err-streams aren't visible or otherwise in use. But the
logging-module can log to files (or even system event logs *me thinks*)
Diez
Yes - syslog is supported on Unix, as well as a host of other ways of
getting information out of your application. See
http://docs.python.org/library/logging.html#streamhandler
This is a list of handlers included with the logging package, starting
with StreamHandler.
Regards,
Vinay Sajip
I think log system is a very good choice.
Happy new year!