Hello everyone.
I'm trying to control a program from a Python program using IPC. Although using a socket is a common choice for such applications, I would like to use SysV message queues because I don't need to parse the stream.
I thought Python had a support of SysV message queues (I have found almost anything I need in Python library modules so far). But Python library seems not supporting SysV message queues yet.
I'm thinking of calling a C function from Python but it seems not so easy.
Although this might not be the most elegant way to do what you want, it's relatively easy to make a C function work with Python. Have a look at http://www.swig.org/
Swig writes a C/Python wrapper for your C code which can be compiled into a shared object library. Then you can import that in Python. Swig is also (rudimentary) supported by distutils, so you don't even need to deal with the generation of the library.
Christian
Example:
> cat src/SomeModule.i %module SomeModuleLib %{ #include "SomeModule.h" %} %include src/SomeModule.c
> swig -python src/SomeModule.i
> gcc -I/sw/include/python2.3 -c src/SomeModule.c -o SomeModule.o
> gcc -I/sw/include/python2.3 -c src/SomeModule_wrap.c -o SomeModule_wrap.o
> gcc -L/sw/lib -bundle -flat_namespace -undefined suppress SomeModule.o SomeModule_wrap.o -o _SomeModuleLib.so
or automatic build from setup.py
from distutils.core import setup, Extension
import os, glob
srcfiles = glob.glob(os.path.join('src', '*.[ci]'))
setup(name="SomePackage",
package_dir={"SomePackage": "lib"},
packages=["SomePackage"],
ext_modules=[Extension("SomePackage._SomeModuleLib", srcfiles,),],)
>>> import SomeModuleLib
-- http://mail.python.org/mailman/listinfo/python-list