Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Segmentation Fault

Reply
Thread Tools

Segmentation Fault

 
 
pycraze
Guest
Posts: n/a
 
      08-28-2006
I would like to ask a question. How do one handle the exception due to
Segmentation fault due to Python ? Our bit operations and arithmetic
manipulations are written in C and to some of our testcases we
experiance Segmentation fault from the python libraries.

If i know how to handle the exception for Segmentation fault , it will
help me complete the run on any testcase , even if i experiance Seg
Fault due to any one or many functions in my testcase.

 
Reply With Quote
 
 
 
 
Simon Forman
Guest
Posts: n/a
 
      08-28-2006
pycraze wrote:
> I would like to ask a question. How do one handle the exception due to
> Segmentation fault due to Python ? Our bit operations and arithmetic
> manipulations are written in C and to some of our testcases we
> experiance Segmentation fault from the python libraries.
>
> If i know how to handle the exception for Segmentation fault , it will
> help me complete the run on any testcase , even if i experiance Seg
> Fault due to any one or many functions in my testcase.


AFAIK, seg fault kills your program dead. There's no exception to
handle. If you're getting seg faults from the python standard library,
that's a pretty serious thing, way more serious than just not-passed
testcases.

An uncaught exception in python should generate a traceback. If it
does, please post that.

Whether it does or not, could you post a minimal example of the code
that causes the seg fault? Python standard lib is fairly robust but of
course not bullet-proof. If there's a way to make it seg fault (and
it's in the standard lib and not your C code) people will want to know.

HTH,
~Simon

 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      08-28-2006
pycraze wrote:
> I would like to ask a question. How do one handle the exception due to
> Segmentation fault due to Python ?


This is confusing. A seg fault kills the process immediately. No
exception (in the Python sense of that word) is raised.

> Our bit operations and arithmetic
> manipulations are written in C


Do you have a Python extension that is written in C, or are you
embedding Python in a C program -- in other words, is a Python script
calling a C function, or is a C program calling a Python function?

> and to some of our testcases we
> experiance Segmentation fault from the python libraries.


What is it that you are calling "the python libraries"? Tell us the
filenames of these libraries. *Show us what is output on your stderr
when you experience "Segmentation fault from the python libraries".*

Was this Python/C combination recently created by current personnel, or
do we have a case of vanished author(s)?

>
> If i know how to handle the exception for Segmentation fault , it will
> help me complete the run on any testcase , even if i experiance Seg
> Fault due to any one or many functions in my testcase.


It would also help if you told us what platform (hardware and software)
that you are running on, what version of Python, and what versions of
any 3rd-party Python modules/packages that may be involved.

Cheers,
John

 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      08-28-2006
pycraze wrote:
> I would like to ask a question. How do one handle the exception due to
> Segmentation fault due to Python ? Our bit operations and arithmetic
> manipulations are written in C and to some of our testcases we
> experiance Segmentation fault from the python libraries.
>
> If i know how to handle the exception for Segmentation fault , it will
> help me complete the run on any testcase , even if i experiance Seg
> Fault due to any one or many functions in my testcase.
>

You will observe, if you look at the list of Python exceptions, that a
segfault isn't among them. A segfault is a trap to the hardware, and
generally indicates that a program is so badly hosed that it wouldn't
make much sense to rely on any further computation in it.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

 
Reply With Quote
 
Duncan Booth
Guest
Posts: n/a
 
      08-28-2006
pycraze wrote:

> I would like to ask a question. How do one handle the exception due to
> Segmentation fault due to Python ? Our bit operations and arithmetic
> manipulations are written in C and to some of our testcases we
> experiance Segmentation fault from the python libraries.
>

From what you said, I guess you mean that you have written some extensions
to Python in C, but that the segmentation fault is generated when you call
standard Python library functions.

Most likely your C code has bugs: quite possibly you have messed up
reference counting so some objects you use are being freed and then the
Python libraries allocate other objects into the same memory. It is very
easy to do that especially if you are in the habit of trying to 'borrow'
references instead of religiously incrementing/decrementing reference
counts everywhere.

Try to eliminate the problem down to the smallest reproducable code sample
and post that.

Another suggestion I would make is to see if you can use ctypes or Pyrex to
form the glue between Python and C so that none of the C code you write
knows anything about Python. That should eliminate some possible sources
for error.
 
Reply With Quote
 
thomas.samson@gmail.com
Guest
Posts: n/a
 
      08-28-2006
"Simon Forman" <(E-Mail Removed)> writes:

> pycraze wrote:
>> I would like to ask a question. How do one handle the exception due to
>> Segmentation fault due to Python ? Our bit operations and arithmetic
>> manipulations are written in C and to some of our testcases we
>> experiance Segmentation fault from the python libraries.
>>
>> If i know how to handle the exception for Segmentation fault , it will
>> help me complete the run on any testcase , even if i experiance Seg
>> Fault due to any one or many functions in my testcase.

>
> AFAIK, seg fault kills your program dead. There's no exception to
> handle. If you're getting seg faults from the python standard library,
> that's a pretty serious thing, way more serious than just not-passed
> testcases.


Segfault handling is platform-dependant... So, at least on unix-like
platform, you can use the signal module to detect segfault:

import signal

def handler(signum, frame):
print 'Segfault detected'
# you may use the stack frame here to help debugging

signal.signal(signal.SIGSEGV, handler)

--
Thomas SAMSON
"You're very sure of your facts, " he said at last, "I
couldn't trust the thinking of a man who takes the Universe
- if there is one - for granted. "
 
Reply With Quote
 
Simon Forman
Guest
Posts: n/a
 
      08-28-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> "Simon Forman" <(E-Mail Removed)> writes:
>
> > pycraze wrote:
> >> I would like to ask a question. How do one handle the exception due to
> >> Segmentation fault due to Python ? Our bit operations and arithmetic
> >> manipulations are written in C and to some of our testcases we
> >> experiance Segmentation fault from the python libraries.
> >>
> >> If i know how to handle the exception for Segmentation fault , it will
> >> help me complete the run on any testcase , even if i experiance Seg
> >> Fault due to any one or many functions in my testcase.

> >
> > AFAIK, seg fault kills your program dead. There's no exception to
> > handle. If you're getting seg faults from the python standard library,
> > that's a pretty serious thing, way more serious than just not-passed
> > testcases.

>
> Segfault handling is platform-dependant... So, at least on unix-like
> platform, you can use the signal module to detect segfault:
>
> import signal
>
> def handler(signum, frame):
> print 'Segfault detected'
> # you may use the stack frame here to help debugging
>
> signal.signal(signal.SIGSEGV, handler)
>
> --
> Thomas SAMSON
> "You're very sure of your facts, " he said at last, "I
> couldn't trust the thinking of a man who takes the Universe
> - if there is one - for granted. "


It's good to know that this is possible. However, it's almost
certainly a bad idea to "catch" seg faults and then just proceed with
further testcases. Printing out debugging information would be pretty
good though.

Peace,
~Simon

 
Reply With Quote
 
John Savage
Guest
Posts: n/a
 
      08-31-2006
"pycraze" <(E-Mail Removed)> writes:
>I would like to ask a question. How do one handle the exception due to
>Segmentation fault due to Python ? Our bit operations and arithmetic
>manipulations are written in C and to some of our testcases we
>experiance Segmentation fault from the python libraries.


You don't happen to be using the MSDOS executable do you? I find I get
a segmentation violation with the MSDOS version when I try to print
coloured text. I think I have narrowed it down further: to the situation
where coloured text extends to or beyond the edge of the screen--maybe
it's the text wrapping that causes the seg fault.
--
John Savage (my news address is not valid for email)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault using Firefox 15.0.2 Keith Lee Firefox 3 04-29-2006 05:45 PM
Xerces on Solaris - Segmentation fault ldvmbs@gmail.com XML 0 05-16-2005 07:21 AM
Xerces XML Parser Segmentation fault with Java Pud XML 0 11-06-2003 05:07 PM
Intel Xeon + Linux + IBM sdk 1.3.1 - getting Segmentation fault Alex Hunsley Java 17 11-06-2003 12:12 AM
Re: segmentation fault exception handling Ivan Vecerina C++ 0 06-29-2003 10:56 PM



Advertisments