472,958 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Segmentation Fault

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.

Aug 28 '06 #1
7 5819
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

Aug 28 '06 #2
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

Aug 28 '06 #3
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

Aug 28 '06 #4
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.
Aug 28 '06 #5
"Simon Forman" <ro*********@yahoo.comwrites:
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. "
Aug 28 '06 #6
th***********@gmail.com wrote:
"Simon Forman" <ro*********@yahoo.comwrites:
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

Aug 28 '06 #7
"pycraze" <de*************@wipro.comwrites:
>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)
Aug 31 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sivignon | last post by:
Hi, I'm writing a php script which deals with 3 ORACLE databases. This script is launch by a script shell on an linux machine like this : /../php/bin/php ./MySript.php (PHP 4.3.3) My script...
3
by: diyanat | last post by:
i am writing a cgi script in C using the CGIC library, the script fails to run, i am using apache on linux error report from apache : internal server error Premature end of script headers:...
16
by: laberth | last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why? Here is what I use : typedef struct noeud { int val; struct noeud *fgauche; struct noeud *fdroit; } *arbre; //for those...
3
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
18
by: Digital Puer | last post by:
Hi, I'm coming over from Java to C++, so please bear with me. In C++, is there a way for me to use exceptions to catch segmentation faults (e.g. when I access a location off the end of an array)?...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
3
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection...
6
by: DanielJohnson | last post by:
int main() { printf("\n Hello World"); main; return 0; } This program terminate just after one loop while the second program goes on infinitely untill segmentation fault (core dumped) on...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.