How to exit from embedded IPython shell?

Andy Zhang andy.zhang at
Tue Sep 9 19:57:10 CEST 2014


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

import IPython

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

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);
        retval = PyRun_AnyFile(stdin, (const char *) "<stdin>");

Many thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list