Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'scripts': 0.03; 'socket': 0.07; 'subject: + ': 0.07; 'scripts,': 0.09; 'python': 0.11; 'suggest': 0.14; 'aiming': 0.16; 'cleanly': 0.16; 'devise': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'processes.': 0.16; 'script,': 0.16; 'subject:embed': 0.16; 'tcp': 0.16; 'though)': 0.16; 'with?': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'app': 0.19; 'module': 0.19; 'trying': 0.19; 'split': 0.19; 'memory': 0.22; 'platforms': 0.22; 'network,': 0.22; 'separate': 0.22; "world's": 0.24; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'unix': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'invoke': 0.31; 'file': 0.32; 'probably': 0.32; 'interface': 0.32; 'run': 0.32; 'running': 0.33; "i'd": 0.34; "can't": 0.35; 'operations': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'module.': 0.36; 'ones,': 0.36; 'done': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'application': 0.37; 'server': 0.38; 'easiest': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'launch': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'even': 0.60; 'read': 0.60; 'most': 0.60; 'simply': 0.61; 'simple': 0.61; "you'll": 0.62; 'making': 0.63; 'kind': 0.63; 'here': 0.66; 'direct': 0.67; 'between': 0.67; '20,': 0.68; 'importantly,': 0.68; 'fact,': 0.69; 'jul': 0.74; 'opens': 0.91; 'from.': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=J8Bd6YxPwYubk7smRqvlae3JZnLmGaQW6YWNbwGalcs=; b=u7tsRCj5WMPn9teD4h8W7W1smclGU4keVjGdCaJ4m2duJ6yh8gyNhqIo3j+enz/KaQ 3dnGwSDvb2iKXymtVXA7EnVNckPrlKEnCu5iV+A3Ktk+PzcVEvU6o5UOmQvmp22WsiMN hY13bhqNQkf+vcKbFaxN5KbdzXfV7Y5loO0UlEV702Ay4iL0HKDZRIJ8jbY3acyOym4g UiD9iHV/OFsR5kQuYkP5aLEftBAQr0pJ7LLeqj2gCpsm03Peoa6vCtLgJnQwx2n0f0g6 eRco+4QN/xopzrj9qw53w0hJRaXzFrQtDZ++D69bEmEUEdBfg8bHuTRQrrhE72T0KFj7 QVWg== MIME-Version: 1.0 X-Received: by 10.52.163.165 with SMTP id yj5mr5504493vdb.104.1374282255363; Fri, 19 Jul 2013 18:04:15 -0700 (PDT) In-Reply-To: <6c1a5595-b2f7-4712-8c9c-be664dd8ed18@googlegroups.com> References: <6c1a5595-b2f7-4712-8c9c-be664dd8ed18@googlegroups.com> Date: Sat, 20 Jul 2013 11:04:15 +1000 Subject: Re: how: embed + extend to control my running app? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374282263 news.xs4all.nl 15924 [2001:888:2000:d::a6]:35146 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50935 On Sat, Jul 20, 2013 at 9:52 AM, David M. Cotter 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