Created
October 26, 2018 08:57
-
-
Save ales-erjavec/ae92eb80080fbd3a26391d4d20d94063 to your computer and use it in GitHub Desktop.
PyQt5 segfault test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from concurrent.futures import ThreadPoolExecutor | |
| from PyQt5.QtCore import Qt, QObject, QCoreApplication | |
| from PyQt5.QtCore import QMetaObject | |
| class TestObject(QObject): | |
| def event(self, event): | |
| return super().event(event) | |
| executor = ThreadPoolExecutor() | |
| app = QCoreApplication([]) | |
| def test(parent=None): | |
| obj = TestObject(parent) | |
| def run(): | |
| nonlocal obj # capture obj in the run's closure | |
| ... | |
| f = executor.submit(run) | |
| # run the event loop until future's completion | |
| @f.add_done_callback | |
| def quit(f): | |
| QMetaObject.invokeMethod(app, "quit", Qt.QueuedConnection) | |
| app.exec() | |
| obj.deleteLater() # delete the object from the event queue | |
| iter_n = 0 | |
| while True: | |
| test(parent=app) | |
| iter_n += 1 | |
| if iter_n % 10 == 0: | |
| print("iter:", iter_n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment