开发者

Isolating pieces of code that segfault

I have a function call that sometimes produces a segfault. Right now I isolate this code by putting it in a separate Python file and doing Popen('python snippet.py') inside of my main script. Is there a more elegant way of doing this on a Unix system?

Update 7/24

I found the following to be convenient

if not os.fork():
  # do stuff that could segfault here

This has the advantage of not having to put all initialization code in a separate file. Apparently there's also multiprocessing module in Python 2.6 th开发者_如何学Pythonat supports inter-process communication


Why not find it and fix it?

strace python yourapp.py yourargs and options >trace.out 2>&1

Then, after it segfaults try tail -50 trace.out and you will see how it leads up to the segfault. Typically it is a pointer that is garbled and points to memory addresses that are not part of the process. It is quite possible for a Python error to create such pointer errors if you are using something like ctypes to access shared libraries.

I

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜