From de11e6315cb6262344fc38b9a1f88f61e5deb8e5 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Mon, 8 Feb 2021 14:11:20 +0800 Subject: [PATCH] let examples have a chance to exit normally cleanup imported module 1) instantiate MainWindow class if present 2) delete attributes from imported module when done --- examples/test_examples.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/examples/test_examples.py b/examples/test_examples.py index ba1037ad..66be7ae0 100644 --- a/examples/test_examples.py +++ b/examples/test_examples.py @@ -212,22 +212,23 @@ def testExamples(frontend, f): import2 = os.path.splitext(os.path.split(fn)[1])[0] code = """ try: - %s + {0} import initExample import pyqtgraph as pg - import %s + import {1} import sys print("test complete") sys.stdout.flush() - import time - while True: ## run a little event loop - pg.QtGui.QApplication.processEvents() - time.sleep(0.01) + pg.Qt.QtCore.QTimer.singleShot(1000, pg.Qt.QtWidgets.QApplication.quit) + pg.Qt.QtWidgets.QApplication.instance().exec_() + names = [x for x in dir({1}) if not x.startswith('_')] + for name in names: + delattr({1}, name) except: print("test failed") raise -""" % (import1, import2) +""".format(import1, import2) if sys.platform.startswith('win'): process = subprocess.Popen([sys.executable], stdin=subprocess.PIPE, @@ -259,8 +260,13 @@ except: if output.endswith('test failed'): fail = True break - time.sleep(1) - process.kill() + start = time.time() + killed = False + while process.poll() is None: + time.sleep(0.1) + if time.time() - start > 2.0 and not killed: + process.kill() + killed = True #res = process.communicate() res = (process.stdout.read(), process.stderr.read()) if (fail or