Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.05; 'log:': 0.05; 'postgresql': 0.07; 'x-mailer:evolution 2.28.3': 0.07; 'python': 0.09; 'cest': 0.09; 'lost.': 0.09; 'newly': 0.09; 'received:212.227.126': 0.09; 'struct': 0.09; 'terminated': 0.09; 'subject:python': 0.11; 'failed.': 0.16; 'received:192.168.11': 0.16; 'reset:': 0.16; 'subject: \n ': 0.16; 'subject:ctypes': 0.16; 'subject:into': 0.16; 'subject:program': 0.16; 'subject:which': 0.16; 'library': 0.16; 'language': 0.16; '(the': 0.16; 'import': 0.20; 'embedding': 0.21; 'select': 0.22; 'tried': 0.23; 'function': 0.26; 'replace': 0.27; 'host': 0.27; 'attempting': 0.28; 'ctypes': 0.28; 'terminating': 0.28; 'hi,': 0.29; 'loaded': 0.30; 'connection': 0.31; 'running': 0.33; 'anyone': 0.33; 'server': 0.33; 'skip:- 10': 0.34; 'to:addr :python-list': 0.35; 'text': 0.35; 'does': 0.36; 'calling': 0.36; 'but': 0.37; 'skip:s 20': 0.37; 'some': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.39; 'received:192.168': 0.40; 'received:de': 0.40; 'caused': 0.60; 'subject:back': 0.62; 'due': 0.68; '11:': 0.84; 'server)': 0.84 Subject: has anybody used ctypes to call back into c program which embeds a python interpreter From: Hannu Krosing To: python-list@python.org Content-Type: text/plain; charset="UTF-8" Date: Sat, 31 Mar 2012 16:33:40 +0200 Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:mRJFI+mHsUvv4YTD//iQ58xtvl5LFo44tZc/43owXxp IJHc01VD3AKaj0Ym7/QMwPVHLhzMb4MvrxFH4ALBc+6p5ttNUX dGigrPSAvf0TAvoAw8emKYK+eKP1ZNtbz5KIpQQHXLUIhdZcLy GKxFXJn8Qmz7x6C+1bQ62dRgyDEiGdPs5K8hLl+hr3zYGpDPOx MQPje/WIEtHN+L1ucsco56otPcYyjq2Ton/xQ2LT/Q8IQYMAEh b26MEemUIlgicwv3iwAg145TT/0Jy7XKLjMI04ViVHqbzV6p5L 7X+zzg1aDlZWVO7GrvllQZEhs4a21RaMnXKOKiL8VAm1hXEPSM FBdb8n/U2sLT/N8mPv+C3w4id/uyUZFxQ3BIta8ps X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1333204443 news.xs4all.nl 6939 [2001:888:2000:d::a6]:45538 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22418 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