Re: How can I catch segmentation fault in python?

2010-11-17 Thread justin
Just checked what is valgrind, sounds promising.
Let me try that.

Thanks a lot,
Justin.

On Nov 17, 9:47 am, Wolfgang Rohdewald  wrote:
> On Mittwoch 17 November 2010, Wolfgang Rohdewald wrote:
>
> > On Mittwoch 17 November 2010, justin wrote:
> > > But the problem is that the code is not mine, and it takes
> > > over a day for me to get the point where the segmentation
> > > fault occurred. Plus, it seems that the point is not
> > > deterministic
>
> > > Still, I think I should at least try to figure out exactly
> > > at which point the segmentation fault occurs, and think
> > > where to go from there according to your kind advice.
>
> > try valgrind
>
> hit the send button too fast...
>
> even if the segmentation fault only happens after a long time
> valgrind might find problems much sooner, and fixing them
> might remove the segmentation fault.
>
> --
> Wolfgang

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I catch segmentation fault in python?

2010-11-17 Thread Wolfgang Rohdewald
On Mittwoch 17 November 2010, Wolfgang Rohdewald wrote:
> On Mittwoch 17 November 2010, justin wrote:
> > But the problem is that the code is not mine, and it takes
> > over a day for me to get the point where the segmentation
> > fault occurred. Plus, it seems that the point is not
> > deterministic
> > 
> > Still, I think I should at least try to figure out exactly
> > at which point the segmentation fault occurs, and think
> > where to go from there according to your kind advice.
> 
> try valgrind

hit the send button too fast...

even if the segmentation fault only happens after a long time
valgrind might find problems much sooner, and fixing them
might remove the segmentation fault.

-- 
Wolfgang
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I catch segmentation fault in python?

2010-11-17 Thread Wolfgang Rohdewald
On Mittwoch 17 November 2010, justin wrote:
> But the problem is that the code is not mine, and it takes
> over a day for me to get the point where the segmentation
> fault occurred. Plus, it seems that the point is not
> deterministic
> 
> Still, I think I should at least try to figure out exactly at
> which point the segmentation fault occurs, and think where to
> go from there according to your kind advice.

try valgrind

-- 
mit freundlichen Grüssen

with my best greetings

Wolfgang Rohdewald

dipl. Informatik Ing. ETH Rohdewald Systemberatung
Karauschenstieg 4
D 21640 Horneburg
Tel.: 04163 826 819
Fax:  04163 826 828
Internet: http://www.rohdewald.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I catch segmentation fault in python?

2010-11-17 Thread justin
On Nov 17, 1:06 am, John Nagle  wrote:
> On 11/16/2010 10:15 PM, swapnil wrote:
>
>
>
>
>
> > On Nov 17, 10:26 am, justin  wrote:
> >> Hi all,
>
> >> I am calling a program written in C inside Python using ctypes,
> >> and it seems that sometimes the program in C crashes while it's being
> >> used in Python.
> >> Even under the circumstances, I want to get the Python program going
> >> by handling the segmentation fault.
>
> >> I've already searched the Internet, but couldn't get the right answer
> >> to catch them.
> >> Could any of you please let me know how to deal with this and catch
> >> the segmentation fault in Python?
>
> >> Thanks,
> >> Justin.
>
> > Segmentation fault isn't exactly an exception that you can catch. It
> > usually means something has gone horribly wrong, like dereferencing
> > invalid pointer, trying to access memory out of process's range. Since
> > if you run out of memory Python simply raises MemoryError exception,
> > which you can catch. So that is not the case for segmentation fault.
>
>     Either fix the program so it doesn't crash,or run the offending
> module and the C code in a subprocess.
>
>                                 John Nagle

Thanks guys for this fast replies,

Turns out that it is a fact that segmentation fault is not what I can
deal with in programming level.
But the problem is that the code is not mine, and it takes over a day
for me to get the point where the segmentation fault occurred.
Plus, it seems that the point is not deterministic

Still, I think I should at least try to figure out exactly at which
point the segmentation fault occurs, and think where to go from there
according to your kind advice.

Again many thanks,
Justin.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I catch segmentation fault in python?

2010-11-16 Thread John Nagle

On 11/16/2010 10:15 PM, swapnil wrote:

On Nov 17, 10:26 am, justin  wrote:

Hi all,

I am calling a program written in C inside Python using ctypes,
and it seems that sometimes the program in C crashes while it's being
used in Python.
Even under the circumstances, I want to get the Python program going
by handling the segmentation fault.

I've already searched the Internet, but couldn't get the right answer
to catch them.
Could any of you please let me know how to deal with this and catch
the segmentation fault in Python?

Thanks,
Justin.


Segmentation fault isn't exactly an exception that you can catch. It
usually means something has gone horribly wrong, like dereferencing
invalid pointer, trying to access memory out of process's range. Since
if you run out of memory Python simply raises MemoryError exception,
which you can catch. So that is not the case for segmentation fault.


   Either fix the program so it doesn't crash,or run the offending
module and the C code in a subprocess.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I catch segmentation fault in python?

2010-11-16 Thread Chris Rebert
On Tue, Nov 16, 2010 at 9:26 PM, justin  wrote:
> Hi all,
>
> I am calling a program written in C inside Python using ctypes,
> and it seems that sometimes the program in C crashes while it's being
> used in Python.
> Even under the circumstances, I want to get the Python program going
> by handling the segmentation fault.
>
> I've already searched the Internet, but couldn't get the right answer
> to catch them.
> Could any of you please let me know how to deal with this and catch
> the segmentation fault in Python?

You can't "catch" it. It's not a mere Exception, it's a fatal error
that effectively crashes the interpreter itself.
At best, you could perhaps use the `multiprocessing` or `subprocess`
modules to segregate the part of your program that uses ctypes and
then try and recover when you detect that the subprocess has crashed.
Instead, if possible, fix the C program and/or ensure that there's not
an error in your ctypes interfacing code.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I catch segmentation fault in python?

2010-11-16 Thread swapnil
On Nov 17, 10:26 am, justin  wrote:
> Hi all,
>
> I am calling a program written in C inside Python using ctypes,
> and it seems that sometimes the program in C crashes while it's being
> used in Python.
> Even under the circumstances, I want to get the Python program going
> by handling the segmentation fault.
>
> I've already searched the Internet, but couldn't get the right answer
> to catch them.
> Could any of you please let me know how to deal with this and catch
> the segmentation fault in Python?
>
> Thanks,
> Justin.

Segmentation fault isn't exactly an exception that you can catch. It
usually means something has gone horribly wrong, like dereferencing
invalid pointer, trying to access memory out of process's range. Since
if you run out of memory Python simply raises MemoryError exception,
which you can catch. So that is not the case for segmentation fault.
-- 
http://mail.python.org/mailman/listinfo/python-list


How can I catch segmentation fault in python?

2010-11-16 Thread justin
Hi all,

I am calling a program written in C inside Python using ctypes,
and it seems that sometimes the program in C crashes while it's being
used in Python.
Even under the circumstances, I want to get the Python program going
by handling the segmentation fault.

I've already searched the Internet, but couldn't get the right answer
to catch them.
Could any of you please let me know how to deal with this and catch
the segmentation fault in Python?

Thanks,
Justin.
-- 
http://mail.python.org/mailman/listinfo/python-list