Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(first': 0.09; 'exit': 0.09; 'subject:How': 0.10; 'python': 0.11; '&&': 0.16; 'eof': 0.16; '\xc2\xa0i': 0.16; 'thanks,': 0.17; '8bit%:5': 0.22; 'input': 0.22; 'import': 0.22; 'python?': 0.22; 'shell': 0.22; 'char': 0.24; 'second': 0.26; 'function': 0.29; 'skip:p 30': 0.29; 'wonder': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'embedding': 0.31; 'null)': 0.31; 'python).': 0.31; 'file': 0.32; 'running': 0.33; 'subject:from': 0.34; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done,': 0.36; 'interact': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'should': 0.36; 'application': 0.37; 'skip:& 10': 0.38; 'to:addr:python- list': 0.38; 'skip:& 20': 0.39; 'embedded': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=TvcetANbamibd218u4ycxs/BtRhnofFxKkzN0VBRF6o=; b=ib8zqZfBYgDbz2bOl52522gaME33VFeYJcRgh1SoAoZoQB3fFLG16IVrgUjgDt+3tz EvOy5EEg1+CCE63Xy547tARMREDaF/OngMGJPOiKV4zVQMmwoPUKAndAgA8FLZPvG2lk Q9SE4eEKd0/lU634/ir0OrUCDzXC/rgoD8VCWd8Ykg9pplp2MIRJDS0qKr4xubgagppf ew5RnFuDJvgPiY6tLPI8STIISoe82/wPFPwDY2/bKlhiJMLZigG0fB7i1+0nStF3F81G hlzZRPZ3uJoyurAUcoo8ROtRJ36HupNYPq3Z0GXPwCVWJXJufj4aPY3LNsZ7+PP0juqu d0yA== MIME-Version: 1.0 X-Received: by 10.112.202.106 with SMTP id kh10mr35480969lbc.66.1410285430498; Tue, 09 Sep 2014 10:57:10 -0700 (PDT) Date: Tue, 9 Sep 2014 13:57:10 -0400 Subject: How to exit from embedded IPython shell? From: Andy Zhang To: python-list@python.org Content-Type: multipart/alternative; boundary=001a11c36a241def6f0502a5aa5a 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: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1410285433 news.xs4all.nl 2899 [2001:888:2000:d::a6]:60343 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77748 --001a11c36a241def6f0502a5aa5a Content-Type: text/plain; charset=UTF-8 Hi, I am embedding IPython inside a c application, by running PYTHONSTARTUP file which is: import IPython IPython.embed() Then the application interact with user input via stdin. After the user is done, she would type EOF. The program should exit, but keep all the python objects in memory, and the user can re-enter python by calling the function again. Because of the embedded IPython, the user needs to enter EOF twice (First EOF exit IPython, second exit outter Python). I wonder whether it is possible to exit the outer Shell in my C code so that user can type one EOF and exit IPython and Python? char *startup = Py_GETENV("PYTHONSTARTUP"); if (startup != NULL && startup[0] != '\0') { FILE *fp = fopen(startup, "r"); if (fp != NULL) { (void) PyRun_SimpleFile(fp, startup); PyErr_Clear(); fclose(fp); } } retval = PyRun_AnyFile(stdin, (const char *) ""); Many thanks, --001a11c36a241def6f0502a5aa5a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

I am embedding IPython inside a c a= pplication, by running PYTHONSTARTUP file which is:

import IPython
IPython.embed()

<= div>Then the application interact with user input via stdin. =C2=A0After th= e user is done, she would type EOF. =C2=A0The program should exit, but keep= all the python objects in memory, and the user can re-enter python by call= ing the function again.

Because of the embedded IP= ython, the user needs to enter EOF twice (First EOF exit IPython, second ex= it outter Python). =C2=A0I wonder whether it is possible to exit the outer = Shell in my C code so that user can type one EOF and exit IPython and Pytho= n?

=C2=A0 =C2=A0 =C2=A0 =C2=A0 char *sta= rtup =3D Py_GETENV("PYTHONSTARTUP");
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 if (startup !=3D NULL && startup[0] !=3D '\0') {=
FILE *fp = =3D fopen(startup, "r");
if (fp !=3D NULL) {
(void) PyRun_SimpleFile(fp, startup);
PyErr_Clear()= ;
fclose(f= p);
}
=
=C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 retval =3D PyRun_AnyFile(stdin, (const char *)= "<stdin>");

Many than= ks,



--001a11c36a241def6f0502a5aa5a--