Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to debug embeding Python?

2 views
Skip to first unread message

Hongtian

unread,
Dec 30, 2008, 1:22:52 AM12/30/08
to
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.

wei...@sina.com

unread,
Dec 30, 2008, 4:23:52 AM12/30/08
to
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')

Diez B. Roggisch

unread,
Dec 30, 2008, 8:32:29 AM12/30/08
to
Hongtian schrieb:

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

Vinay Sajip

unread,
Dec 30, 2008, 11:57:57 PM12/30/08
to
On Dec 30, 1:32 pm, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
> 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

Hongtian

unread,
Dec 31, 2008, 8:42:56 PM12/31/08
to
Thanks all of you, my friends.

I think log system is a very good choice.

Happy new year!

0 new messages