has anybody used ctypes to call back into c program which embeds apython interpreter

Discussion in 'Python' started by Hannu Krosing, Mar 31, 2012.

  1. Hi,

    I want to use ctypes to use some functions from postgreSQL server which
    embeds python interpreter as language pl/python.

    That is I want to use ctypes to call _back_ to some internal functions
    in the server

    What I tried is the following:

    hannu=# create or replace function send_raw_notice(rn_text text)
    returns text
    language plpythonu
    as
    $$

    from ctypes import *
    import struct

    pg = cdll.LoadLibrary('/usr/lib/postgresql/9.1/bin/postmaster')
    pg.pq_flush()

    return rn_text
    $$;
    CREATE FUNCTION
    hannu=# select send_raw_notice('so you see me?');
    The connection to the server was lost. Attempting reset: Failed.
    !>

    This caused a segfault:

    2012-03-31 16:28:24 CEST LOG: server process (PID 8739) was terminated
    by signal 11: Segmentation fault
    2012-03-31 16:28:24 CEST LOG: terminating any other active server
    processes

    I suspect it is due to not calling into the host program (the running
    server) but into a newly loaded and uninitialized copy of postmaster
    loaded as library


    Does anyone have ideas how to call into the embedding c program from
    ctypes ?

    --------------
    Hannu
     
    Hannu Krosing, Mar 31, 2012
    #1
    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. NagitaK
    Replies:
    6
    Views:
    374
    NagitaK
    Sep 13, 2003
  2. News Reader

    Has anybody used cx_bsdiff?

    News Reader, Oct 25, 2005, in forum: Python
    Replies:
    0
    Views:
    400
    News Reader
    Oct 25, 2005
  3. Liang Chen
    Replies:
    11
    Views:
    484
  4. cwdjrxyz
    Replies:
    1
    Views:
    731
    dorayme
    Jan 28, 2011
  5. Douglas Shearer

    Redcloth ignore YouTube embeds?

    Douglas Shearer, Dec 3, 2007, in forum: Ruby
    Replies:
    2
    Views:
    146
    Matt Todd
    Dec 4, 2007
Loading...

Share This Page