ipdb, multiple threads and autoreloading programs causing ProgrammingError

ぃ、小莉子 提交于 2019-12-10 13:18:51

问题


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.


回答1:


You can always run Django in single threaded mode

python manage.py runserver --nothreading


来源:https://stackoverflow.com/questions/16580234/ipdb-multiple-threads-and-autoreloading-programs-causing-programmingerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!