prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 717 forks source link

Fix `__breakpointhook__` when it's called from another thread. #1738

Closed jonathanslenders closed 1 year ago

jonathanslenders commented 1 year ago

Calling breakpoint() in a thread other than the one running the Application would crash the process with a "RuntimeError: no running event loop".

  File ".../site-packages/prompt_toolkit/application/application.py", line 1026, in trace_dispatch
    with app.input.detach():
  File ".../lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File ".../site-packages/prompt_toolkit/input/vt100.py", line 203, in _detached_input
    loop = get_running_loop()
RuntimeError: no running event loop