How to debug embeding Python?

H

Hongtian

Hi Friends,

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.
 
W

weir009

Using udp to send out message is a convenient way, you may define a
log function like following, and start a udp server to lisen.

#############
from socket import *

udpSock = socket(AF_INET,SOCK_DGRAM)

def log(s):
udpSock.sendto(s, ('127.0.0.1', 514))

log('hello')
 
D

Diez B. Roggisch

Hongtian said:
Hi Friends,

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?

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
 
V

Vinay Sajip

Additionally, printing might not work reliably in cases where the
stdout/err-streams aren't visible or otherwise in use. But thelogging-module can log to files (or even system event logs *me thinks*)

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
 
H

Hongtian

Thanks all of you, my friends.

I think log system is a very good choice.

Happy new year!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top