'How abort thread when QMainWindow is closed?

In this MWE, a popup window is created and after 8 seconds it prints 'done' in the console. If the popup window is closed before 'done' is printed, then after a few seconds it still prints 'done'. I would like that nothing is printed if I close the popup window before 'done' is printed. How can do this?

import time
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
import threading

class CustomMainWindow(QMainWindow):
    def __init__(self):
        super(CustomMainWindow, self).__init__()
        myDataLoop = threading.Thread(name = 'myDataLoop', target = dataSendLoop, daemon = True, args = ())
        myDataLoop.start()
        self.show()
        return

def dataSendLoop():
    #actually a lengthy calculation
    time.sleep(8)
    print('done')

if __name__== '__main__':
    app =QApplication(sys.argv)
    myGUI = CustomMainWindow()
    sys.exit(app.exec_())    


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source