Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipdb, multiple threads and autoreloading programs causing ProgrammingError

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.

like image 431
Mikko Ohtamaa Avatar asked May 16 '13 06:05

Mikko Ohtamaa


1 Answers

You can always run Django in single threaded mode

python manage.py runserver --nothreading
like image 159
istib Avatar answered Oct 14 '22 18:10

istib