Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError on closing plot in pyqtgraph 0.10.0 & python 3.6 #603

Closed
jphdotam opened this issue Nov 6, 2017 · 7 comments
Closed

ReferenceError on closing plot in pyqtgraph 0.10.0 & python 3.6 #603

jphdotam opened this issue Nov 6, 2017 · 7 comments

Comments

@jphdotam
Copy link
Contributor

jphdotam commented Nov 6, 2017

I have a plot as follows:

        app = QtGui.QApplication([])

        win = pg.GraphicsWindow(title="ETT: {} / Stage: {} / Lead: {}".format(self.patient_id,self.stage,self.lead))
        win.setWindowTitle("ETT: {} / Stage: {} / Lead: {}".format(self.patient_id,self.stage,self.lead))

        plot = win.addPlot(title=self.lead, x=self.x, y=self.y, pen='b')
        plot.setYRange(0, 35, padding=0)
        plot.setXRange(300, 1200, padding=0)

        marker_qrs_onset.sigPositionChanged.connect(update_qrs)
        marker_qrs_offset.sigPositionChanged.connect(update_qrs)

        app.instance().exec_()

        print("App closed")

When I close the plotting window, the print() statement never runs, and instead I get:

Traceback (most recent call last):
  File "/anaconda/lib/python3.6/site-packages/pyqtgraph/__init__.py", line 312, in cleanup
    if isinstance(o, QtGui.QGraphicsItem) and isQObjectAlive(o) and o.scene() is None:
ReferenceError: weakly-referenced object no longer exists

If I add an exception for this ReferenceError to the cleanup() function in pyqtgraph's init.py then it works perfectly, as it now reads:

    for o in gc.get_objects():
        try:
            if isinstance(o, QtGui.QGraphicsItem) and isQObjectAlive(o) and o.scene() is None:
                if getConfigOption('crashWarning'):
                    sys.stderr.write('Error: graphics item without scene. '
                        'Make sure ViewBox.close() and GraphicsView.close() '
                        'are properly called before app shutdown (%s)\n' % (o,))
                
                s.addItem(o)
        except RuntimeError:  ## occurs if a python wrapper no longer has its underlying C++ object
            continue
        except ReferenceError: ##ADDED
            continue
    _cleanupCalled = True

This is tested on pyathon 3.5 & 3.6 on Windows and on Mac.

@toinsson
Copy link

toinsson commented Dec 8, 2017

could also be:

except (RuntimeError, ReferenceError):

I get this issue when running pyqtgraph with tensorflow. This is referenced on SO.

jphdotam added a commit to jphdotam/pyqtgraph that referenced this issue Dec 18, 2017
Prevents a ReferenceError being thrown when PyQtGraph tries to put TensorFlow stuff onto a QGraphicsScene() on cleanup - see pyqtgraph#603 and https://stackoverflow.com/questions/41542571/pyqtgraph-tries-to-put-tensorflow-stuff-onto-a-qgraphicsscene-on-cleanup
Billy4195 pushed a commit to Billy4195/pyqtgraph that referenced this issue Apr 2, 2018
Prevents a ReferenceError being thrown when PyQtGraph tries to put TensorFlow stuff onto a QGraphicsScene() on cleanup - see pyqtgraph#603 and https://stackoverflow.com/questions/41542571/pyqtgraph-tries-to-put-tensorflow-stuff-onto-a-qgraphicsscene-on-cleanup
@kai66673
Copy link

kai66673 commented Apr 4, 2018

Does it fixed?

@retsyo
Copy link

retsyo commented Dec 29, 2018

it seems that this Error still lives in current pyqtgraph

@ixjlyons
Copy link
Member

#613 has been merged, so this should be fixed, though it hasn't made it into a pyqtgraph release yet. Feel free to re-open if you're still seeing this problem using the latest develop branch.

@horsto
Copy link

horsto commented Feb 14, 2020

Has anybody experienced problems with that again?
I still run into this error, but maybe I am doing something wrong:

if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = SessionViewer()
    main.resize(1400,800)
    main.show()
    sys.exit(app.exec_())

On closing window:

WARNING: Traceback (most recent call last):
  File "/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/pyqtgraph/__init__.py", line 312, in cleanup
    if isinstance(o, QtGui.QGraphicsItem) and isQObjectAlive(o) and o.scene() is None:
ReferenceError: weakly-referenced object no longer exists
Abort trap: 6

@ixjlyons
Copy link
Member

@horsto are you using pyqtgraph version 0.10.0? My comment above is still accurate -- you could install the 0.11.0 release candidate with pip install --pre "pyqtgraph>0.10" and that should resolve the issue. I don't think it's of much practical consequence aside from generating the error message though.

@horsto
Copy link

horsto commented Feb 16, 2020

Thanks @ixjlyons! Yes, I was on 0.10.0. I updated to 0.11.0 and that indeed fixed the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants