Added workaround for Qt crash-at-exit bug (make sure that all GraphicsItems live in a scene before exiting)
This commit is contained in:
parent
6932c34126
commit
364337083f
24
__init__.py
24
__init__.py
@ -119,11 +119,27 @@ from .SignalProxy import *
|
|||||||
from .ptime import time
|
from .ptime import time
|
||||||
|
|
||||||
|
|
||||||
|
## Workaround for Qt exit crash:
|
||||||
|
## ALL QGraphicsItems must have a scene before they are deleted.
|
||||||
|
## This is potentially very expensive, but preferred over crashing.
|
||||||
|
import atexit
|
||||||
|
def cleanup():
|
||||||
|
if QtGui.QApplication.instance() is None:
|
||||||
|
return
|
||||||
|
import gc
|
||||||
|
s = QtGui.QGraphicsScene()
|
||||||
|
for o in gc.get_objects():
|
||||||
|
try:
|
||||||
|
if isinstance(o, QtGui.QGraphicsItem) and o.scene() is None:
|
||||||
|
s.addItem(o)
|
||||||
|
except RuntimeError: ## occurs if a python wrapper no longer has its underlying C++ object
|
||||||
|
continue
|
||||||
|
atexit.register(cleanup)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Convenience functions for command-line use
|
## Convenience functions for command-line use
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
plots = []
|
plots = []
|
||||||
images = []
|
images = []
|
||||||
QAPP = None
|
QAPP = None
|
||||||
@ -176,8 +192,8 @@ show = image ## for backward compatibility
|
|||||||
|
|
||||||
|
|
||||||
def mkQApp():
|
def mkQApp():
|
||||||
if QtGui.QApplication.instance() is None:
|
|
||||||
global QAPP
|
global QAPP
|
||||||
|
if QtGui.QApplication.instance() is None:
|
||||||
QAPP = QtGui.QApplication([])
|
QAPP = QtGui.QApplication([])
|
||||||
|
return QAPP
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user