Skip to content

Instantly share code, notes, and snippets.

@ales-erjavec
Created October 26, 2018 08:57
Show Gist options
  • Select an option

  • Save ales-erjavec/ae92eb80080fbd3a26391d4d20d94063 to your computer and use it in GitHub Desktop.

Select an option

Save ales-erjavec/ae92eb80080fbd3a26391d4d20d94063 to your computer and use it in GitHub Desktop.
PyQt5 segfault test
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