Segmentation Fault on CDLL reloading

Discussion in 'Python' started by Marcus.CM, Aug 30, 2008.

  1. Marcus.CM

    Marcus.CM Guest

    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
     
    Marcus.CM, Aug 30, 2008
    #1
    1. Advertising

  2. 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
     
    Diez B. Roggisch, Aug 30, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley
    Replies:
    17
    Views:
    879
  2. Pud
    Replies:
    0
    Views:
    593
  3. Replies:
    0
    Views:
    545
  4. Ivan Vecerina
    Replies:
    0
    Views:
    492
    Ivan Vecerina
    Jun 29, 2003
  5. Helmut Jarausch

    ctypes CDLL - which paths are searched?

    Helmut Jarausch, Jan 21, 2008, in forum: Python
    Replies:
    4
    Views:
    1,422
    Thomas Heller
    Jan 22, 2008
Loading...

Share This Page