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

Thomas Kluyver takowl@gmail....
Tue Jul 24 04:04:37 CDT 2012

On 11 July 2012 20:58, Matt Anderson <manderso@broadcom.com> wrote:
> Several bigger issues I encountered revolve around threading. Our
> application can run headless, and the cmd.Cmd shell (when active) does not
> run in the main thread.  The current version of IPython installs at-exit
> handlers when a shell is created or starts up, including functionality to
> close/save the history session when the program exits.  An exception gets
> thrown during the exit process though: “ProgrammingError: SQLite objects
> created in a thread can only be used in that same thread.” The ipython shell
> created the sqlite db object in the cmd.Cmd’s thread, and the at-exit
> handlers always (or at least in most cases / our case) run in the main
> thread.

Good question, but I don't think I have a good answer. I didn't think
about running IPython in a secondary thread.

> I understand that there is a workaround to open a sqlite3 connection in a
> way that suppresses this behavior, but IPython doesn’t open the connection
> in that way by default, and doesn’t seem to provide a hook to do this short
> of subclassing the TerminalInteractiveClass or the InteractiveShellEmbed
> class and writing one’s own init_history() method, and further subclassing
> the HistoryManager and overriding its init_db() method.

Yes, we've come across the flag before, but it is undocumented (last
time I checked), so we're wary of using it in case it has some major


More information about the IPython-dev mailing list