On Sat, Jul 20, 2013 at 9:52 AM, David M. Cotter <m...@davecotter.com> wrote:
> i'd like my app to be "available" to python while it's running.
>
> for example, say my app is "FooBar.app".
>
> when my FooBar.app is running, now there is a python interface available to 
> python, and the user can write python scripts to make use of it.
>
> with their scripts, they can control my running application
>
> when FooBar.app is NOT running, perhaps making use of any of the python 
> functions of "FooBar.app" would either return an error, or possibly launch 
> "FooBar.app"?  or do nothing since it's not running?

Interfacing C and Python like you suggest can't be done with
embedding, because that requires that your app be already running, and
probably not by having your code run as a pure module. In fact, I
would actually suggest that you devise a separate protocol between
your app and the Python script, and run them as separate processes.
That way, they run independently, and you may (platform-specific code
required here though) be able to invoke your app; most importantly,
you'll be able to cleanly handle multiple Python scripts trying to
control you simultaneously.

What platforms are you aiming at? If it's just for Unix-like ones, the
easiest way is probably to create a Unix domain socket, which the
Python program can write to and/or read from. With a protocol based
around simple operations like that, your Python module need not even
involve C code - it simply opens a socket file and uses standard I/O
methods on it. Alternatively, you may want to consider a TCP socket,
which would let you split the client and server across a network, or
possibly direct shared memory access.

The world's your oyster. What kind of sauce would you like it with?

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to