ipdb
ipdb copied to clipboard
Infinite repetition of `AttributeError: '_UnixSelectorEventLoop' object has no attribute '_ssock'` when exception raised in log handler
When an exception occurs in a logging handler and I run the script through ipdb, ipdb attempts to stop at the exception. This results in an infinite repetition of AttributeError: '_UnixSelectorEventLoop' object has no attribute '_ssock' alternating with the custom exception in the log handler.
Running this script with python -mipdb:
import sys
import logging
class MyHandler(logging.StreamHandler):
def emit(self, record):
raise RuntimeError("nooo")
super().emit(record)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(MyHandler(sys.stderr))
logger.warning("test")
an excerpt from the console output:
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/unix_events.py", line 58, in close
super().close()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/selector_events.py", line 92, in close
self._close_self_pipe()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/selector_events.py", line 99, in _close_self_pipe
self._remove_reader(self._ssock.fileno())
AttributeError: '_UnixSelectorEventLoop' object has no attribute '_ssock'
Post mortem debugger finished. The mwe108.py will be restarted
> /home/gholl/checkouts/2019_iafe/devel_code/mwe/mwe108.py(1)<module>()
----> 1 import sys
2 import logging
3
Exception in thread Thread-29889:
Traceback (most recent call last):
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 807, in run
loop = get_event_loop()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-29889'.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/IPython/terminal/debugger.py", line 122, in in_thread
line = self.pt_app.prompt()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1013, in prompt
return self.app.run(set_exception_handler=set_exception_handler)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 813, in run
loop = new_event_loop()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/events.py", line 758, in new_event_loop
return get_event_loop_policy().new_event_loop()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/events.py", line 656, in new_event_loop
return self._loop_factory()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/unix_events.py", line 54, in __init__
super().__init__(selector)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/selector_events.py", line 59, in __init__
logger.debug('Using selector: %s', selector.__class__.__name__)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1422, in debug
self._log(DEBUG, msg, args, **kwargs)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1577, in _log
self.handle(record)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1587, in handle
self.callHandlers(record)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1649, in callHandlers
hdlr.handle(record)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 950, in handle
self.emit(record)
File "/home/gholl/checkouts/2019_iafe/devel_code/mwe/mwe108.py", line 6, in emit
raise RuntimeError("nooo")
RuntimeError: nooo
Exception ignored in: <function BaseEventLoop.__del__ at 0x7f695ff63430>
Traceback (most recent call last):
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/base_events.py", line 656, in __del__
self.close()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/unix_events.py", line 58, in close
super().close()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/selector_events.py", line 92, in close
self._close_self_pipe()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/selector_events.py", line 99, in _close_self_pipe
self._remove_reader(self._ssock.fileno())
AttributeError: '_UnixSelectorEventLoop' object has no attribute '_ssock'
Traceback (most recent call last):
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/ipdb/__main__.py", line 276, in main
pdb._runscript(mainpyfile)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/pdb.py", line 1573, in _runscript
self.run(statement)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/bdb.py", line 580, in run
exec(cmd, globals, locals)
File "<string>", line 1, in <module>
File "/home/gholl/checkouts/2019_iafe/devel_code/mwe/mwe108.py", line 1, in <module>
import sys
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1446, in warning
self._log(WARNING, msg, args, **kwargs)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1577, in _log
self.handle(record)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1587, in handle
self.callHandlers(record)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1649, in callHandlers
hdlr.handle(record)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 950, in handle
self.emit(record)
File "/home/gholl/checkouts/2019_iafe/devel_code/mwe/mwe108.py", line 6, in emit
raise RuntimeError("nooo")
RuntimeError: nooo
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /home/gholl/checkouts/2019_iafe/devel_code/mwe/mwe108.py(6)emit()
5 def emit(self, record):
----> 6 raise RuntimeError("nooo")
7 super().emit(record)
Exception in thread Thread-29890:
Traceback (most recent call last):
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 807, in run
loop = get_event_loop()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-29890'.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/IPython/terminal/debugger.py", line 122, in in_thread
line = self.pt_app.prompt()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1013, in prompt
return self.app.run(set_exception_handler=set_exception_handler)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 813, in run
loop = new_event_loop()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/events.py", line 758, in new_event_loop
return get_event_loop_policy().new_event_loop()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/events.py", line 656, in new_event_loop
return self._loop_factory()
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/unix_events.py", line 54, in __init__
super().__init__(selector)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/asyncio/selector_events.py", line 59, in __init__
logger.debug('Using selector: %s', selector.__class__.__name__)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1422, in debug
self._log(DEBUG, msg, args, **kwargs)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1577, in _log
self.handle(record)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1587, in handle
self.callHandlers(record)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 1649, in callHandlers
hdlr.handle(record)
File "/data/gholl/miniconda3/envs/py38/lib/python3.8/logging/__init__.py", line 950, in handle
self.emit(record)
File "/home/gholl/checkouts/2019_iafe/devel_code/mwe/mwe108.py", line 6, in emit
raise RuntimeError("nooo")
RuntimeError: nooo
Exception ignored in: <function BaseEventLoop.__del__ at 0x7f695ff63430>
Traceback (most recent call last):
...and this repeats on indefinitely. The only change I can see is that the thread ID increases by one.
Attempting to interrupt this with Ctrl+C stops the deluge of console output and instead adds a single line ^C--KeyboardInterrupt--, but does not stop the programme. Interrupting with Ctrl+</kbd> stops the programme with ^\Quit (core dumped).
With regular pdb this problem does not occur, instead I am put into the debugger where the exception is raised.
I'm using ipdb 0.13.3, ipython 7.18.1, python 3.8.6, on openSUSE 15.0.
ipdb is a light wrapper arount IPython debugger.
I see in the traceback that there is an issue with prompt-toolkit which makes me believe this is an issue to be reported to IPython.