Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Segmentation Fault on CDLL reloading

Reply
Thread Tools

Segmentation Fault on CDLL reloading

 
 
Marcus.CM
Guest
Posts: n/a
 
      08-30-2008
Hi,

I use the following ctype to load a .so library in Linux.

vr = ctypes.CDLL(sstr)

And the following to release it so that i can reload the library without
quiting the python script.

_ctypes.dlclose(vr._handle)

These calls are guarded by a writer lock and access to it guarded by a
reader lock which i got from recipe :
http://code.activestate.com/recipes/413393/

The problem is during the re-loading of the library occasionally the
python script will abort with "Segmentation Fault". This is like 1 out
of 10 times it can happen and that
is good enough to kill the application.

Is there any reason to this or how to do i prevent it?


Marcus .CM




 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      08-30-2008
Marcus.CM schrieb:
> Hi,
>
> I use the following ctype to load a .so library in Linux.
>
> vr = ctypes.CDLL(sstr)
> And the following to release it so that i can reload the library without
> quiting the python script.
>
> _ctypes.dlclose(vr._handle)
>
> These calls are guarded by a writer lock and access to it guarded by a
> reader lock which i got from recipe :
>
> The problem is during the re-loading of the library
> occasionally the python script will abort with "Segmentation Fault".
> This is like 1 out of 10 times it can happen and that
> is good enough to kill the application.
>
> Is there any reason to this or how to do i prevent it?


Short answer: yes, there is a reason, no, you can't prevent it.

Of course there is a reason for this. Segfaults don't happen by
chance... And one can't prevent segfaults from killing the interpreter,
because the OS is responsible for that.

Now what would I do?

- don't care. Or does the DLL frequently change when the program is
deployed? Or to ask different: why do you need unloading/reloading at all?

- debug it. Write a script that exposes the behavior. The fire up GDB
with python, do "set args <myscript>" and run. When the segfault occurs,
look into the traceback with "bt". If the problem is in the DLL-code,
see what's causing it. If it's in ctypes (or the python-interpreter) -
well, there is a ctypes mailing lisk to ask for help.

Diez
 
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
ctypes CDLL - which paths are searched? Helmut Jarausch Python 4 01-22-2008 01:42 PM
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



Advertisments