lxqt / qtermwidget

The terminal widget for QTerminal
https://lxqt.github.io
GNU General Public License v2.0
485 stars 247 forks source link

Builtin close() method does not destroy QTermWidget gracefully #535

Open willbelr opened 4 months ago

willbelr commented 4 months ago

When close() method is called on QTermWidget, it appears to close, yet the widget is not deleted properly.

Expected Behavior

close() method should close and delete the widget gracefully, so that memory is freed and garbage collected in Python.

Current Behavior

Despite that the close() method makes the widget disappear, it is not destroyed until the parent object is deleted. At this moment, an error message is thrown: virtual KPtyProcess::~KPtyProcess() the terminal process is still running, trying to stop it by SIGHUP

Steps to Reproduce

In the example below, QTermWidget is added to a QMainWindow. When close is called on QTermWidget, it disappear as expected, without error. However, as either deleteLater is called on the terminal (trigger 1), or close is called on the container widget (trigger 2), this error is shown;

virtual KPtyProcess::~KPtyProcess() the terminal process is still running, trying to stop it by SIGHUP

#!/usr/bin/env python3
import sys
from PyQt5 import QtWidgets, QtCore
from QTermWidget import QTermWidget

class Container(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.term = Terminal()
        self.setCentralWidget(self.term)
        self.show()
        QtCore.QTimer.singleShot(5000, self.close)  # Trigger 2

class Terminal(QTermWidget):
    def __init__(self):
        super().__init__(1)
        QtCore.QTimer.singleShot(1000, self.close)  # No error
        QtCore.QTimer.singleShot(2000, self.deleteLater)  # Trigger 1

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    container = Container()
    app.exec()
System Information