[IPython-dev] migration issues, embedding latest IPython in another application

Thomas Kluyver takowl@gmail....
Tue Jul 24 10:05:26 CDT 2012

On 24 July 2012 15:36, Matt Anderson <manderso@broadcom.com> wrote:
> However, it would be really useful, in cases like mine, to enable this type of database connection by  configuration, rather than needing to do multiple subclassings and re-writing of core functions.

I'm not sure that I'd expose it through the actual config system, but
perhaps a class attribute that your application can override. If you
want to prepare a pull request with this, I think it would get

> Alternatively, maybe there is some other way to shut down the database connection, at thread shutdown time instead of at program shutdown time?  Either automatically (by a per-thread equivalent of the program-wide at-exit system, if such a thing does or could exist).

I don't know of any per-thread equivalent to atexit.

> Or maybe by hook (ie, a way to turn the at-exit registration off, and provide some method on the interactive shell that could be called in the that would shut down the database connection safely from the correct thread, delegating responsibility to the programmer embedding the shell to do the shutdown correctly).

That sounds more feasible.

> Or possibly, at the end of the interactive shell REPL loop, just before control is passed back to the main program (in the case of the embedded shell)?

Possible but tricky. An embedding program can have a shell object that
it reuses, so control passes back and forth between the shell and the
embedding application. The database connection should last while the
shell does, but as I understand it, __del__ methods are not reliably
called when the interpreter is shutting down.


More information about the IPython-dev mailing list