Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77748 > unrolled thread

How to exit from embedded IPython shell?

Started byAndy Zhang <andy.zhang@gmail.com>
First post2014-09-09 13:57 -0400
Last post2014-09-09 13:57 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  How to exit from embedded IPython shell? Andy Zhang <andy.zhang@gmail.com> - 2014-09-09 13:57 -0400

#77748 — How to exit from embedded IPython shell?

FromAndy Zhang <andy.zhang@gmail.com>
Date2014-09-09 13:57 -0400
SubjectHow to exit from embedded IPython shell?
Message-ID<mailman.13913.1410285433.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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 *) "<stdin>");

Many thanks,

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web