Skip to content

Commit

Permalink
Fix memory leak in Qt event loop integration (#14240) (#14251)
Browse files Browse the repository at this point in the history
The QEventLoop object, `event_loop`, created in
`IPython/terminal/pt_intputhooks/qt.py` L58 is not deleted when exiting
the scope as passing `app` to the constructor parents the object to
`app`. This creates a memory leak as QEventLoop objects are being
accumulated.

The issue was originally reported by @pag who also suggested the fix.

`pytest IPython/terminal/tests/` runs through without errors. I have
tested the changes and see no more accumulation of `QEventLoop` objects.

This fixes #14240
  • Loading branch information
Carreau committed Nov 24, 2023
2 parents c7aea08 + b033ecc commit c0a699d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions IPython/terminal/pt_inputhooks/qt.py
Expand Up @@ -84,3 +84,7 @@ def inputhook(context):
_exec(event_loop)
finally:
notifier.setEnabled(False)

# This makes sure that the event loop is garbage collected.
# See issue 14240.
event_loop.setParent(None)

0 comments on commit c0a699d

Please sign in to comment.