ipdb, multiple threads and autoreloading programs causing ProgrammingError
Asked Answered
M

1

6

I am using ipdb debugger to debug multithreaded web applications locally (Django, Plone). Often ipdb seems to get confused because of the autoreload which happens when I am on the debug prompt. The resulting stack trace comes up

/Users/mikko/code/xxxx/venv/lib/python2.7/site-packages/IPython/core/history.pyc in writeout_cache(self, conn)
    605         with self.db_input_cache_lock:
    606             try:
--> 607                 self._writeout_input_cache(conn)
    608             except sqlite3.IntegrityError:
    609                 self.new_session(conn)

/Users/mikko/code/xxxx/venv/lib/python2.7/site-packages/IPython/core/history.pyc in _writeout_input_cache(self, conn)
    589             for line in self.db_input_cache:
    590                 conn.execute("INSERT INTO history VALUES (?, ?, ?, ?)",
--> 591                                 (self.session_number,)+line)
    592
    593     def _writeout_output_cache(self, conn):

ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 4546363392 and this is thread id 140735211872640

After this, either the program cannot be closed (hanging threads) or ipdb itself stops working.

Is there a way to migitate this issue with ipdb and make it more multi-thread / autoreload safe?

EDIT: Clarified the question a bit, as I believe this might be underlying IPython issues. There could be some kind of workaround with making IPython simply discard history on the reload or disabling problematic IPython SQLite writes some other way.

Mair answered 16/5, 2013 at 6:15 Comment(2)
@MIkkoOhtamma, how are you enabling autoreload in ipdb? I know of this extension:ipython.org/ipython-doc/3/config/extensions/autoreload.html. If I enable this extension in ipython, and if I use ipdb, while running the python file in ipython, will ipdb automatically reload statements in the python file, when using n, j etc?Eldridgeeldritch
Related: github.com/gotcha/ipdb/issues/51Sayce
P
5

You can always run Django in single threaded mode

python manage.py runserver --nothreading
Pushup answered 17/1, 2014 at 2:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.