pythonpython-3.xipythonpython-3.7ipdb

Trying to set ipdb.set_trace(): RuntimeError: There is no current event loop in thread 'Thread-....'


I'm using Miniconda 3 on Windows 7, trying to use ipdb to start debugging process in my program. I have installed IPython and ipdb of course (in virtualenv).

Test program:

#!/usr/bin/env python

import ipdb

def a():
    for i in range(10):
        print(i)
    ipdb.set_trace()
    print(100)

a()

What I get is that Python starts going into infinite loop spewing exceptions like this over and over:

Exception in thread Thread-3398:
Traceback (most recent call last):
  File "C:\ACME\Dev\Miniconda3\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\ACME\Dev\Miniconda3\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\ACME\Dev\projects\example\venv\lib\site-packages\IPython\terminal\debugger.py", line 102, in in_thread
    line = self.pt_app.prompt()
  File "C:\ACME\Dev\projects\example\venv\lib\site-packages\prompt_toolkit\shortcuts\prompt.py", line 992, in prompt
    return get_event_loop().run_until_complete(self._dumb_prompt(self.message))
  File "C:\ACME\Dev\Miniconda3\lib\asyncio\events.py", line 644, in get_event_loop
    % threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-3398'.

What could possibly the reason for this and how to fix that?

Versions:

Python 3.7.6

ipdb==0.13.3
ipykernel==5.3.0
ipython==7.15.0
ipython-genutils==0.2.0
ipywidgets==7.5.1

(I list all packages that I found related to IPython, I also have Jupyter installed if that matters).


Solution

  • I replaced old style with new code fragment

    import ipdb;
    ipdb.set_trace() 
    

    for example:

    from IPython.core import debugger
    debug = debugger.Pdb().set_trace
    
    def buggy_method():
        debug()
    

    I fixed this issue. see reference on https://github.com/ipython/ipython/pull/9731/