Qt Application Crash when calling app.quit() in PyTango 9.2.0 (it works with PyTango 8.1.6)

Hi Tangoers,
We try to migrate from PyTango 8.1.6 to 9.2 for our Windows clients.
As we did’nt manage yet to compile PyTango 9.2.3, I use a msi installer for PyTango9.2.0.
We use Python 2.7 32b.

With PyTango9.2.0 within a Qt Application,
if I subscribe to an attribute using pyds.subscribe_event
then Python crashed when I call :
app = QtGui.QApplication(sys.argv)
app.quit()

The same code works with PyTango 8.1.3.
An example is attached.

If somebody could tell me if it works on Windows with PyTango 9.2.3, it would motive us to compile !
launch:

  • DeclareDS
  • TestDevice
  • Client
  • Push OK

If you have a workaround …
Cheers,
Christophe

sample code for the client :

class EventManager():
    
    def __init__(self,deviceAdr, attrAdr,fct,app):
        #Subscribe to the counter
        self.pyds = PyTango.DeviceProxy(deviceAdr)
        self.id_event = self.pyds.subscribe_event(attrAdr, PyTango.EventType.CHANGE_EVENT, self.ReceiveTangoEvent, stateless = True)
        self.app = app
        
        self.wd = QtGui.QLabel("TEST")
        self.wd.show()
        
        #The QUIT button close the application
        self.wdButton = QtGui.QPushButton("QUIT")
        self.wdButton.clicked.connect(self.stop)
        self.wdButton.show()

        #Create a Signal to display the Tango Value
        QtCore.QObject.connect(Qt.qApp, QtCore.SIGNAL("updateData(PyQt_PyObject)"),self.UpdateGui)
        
    def ReceiveTangoEvent(self,event):
        print str(event.attr_value.value)
        Qt.qApp.emit(QtCore.SIGNAL("updateData(PyQt_PyObject)"),str(event.attr_value.value))        

    def UpdateGui(self,data):
        self.wd.setText(data)

    #Called by the QUIT button (OK in PyTango 8.1.6, CRASH in PyTango 9.2.0)
    def stop(self):        
        QtCore.QObject.disconnect(Qt.qApp, QtCore.SIGNAL("updateData(PyQt_PyObject)"),self.UpdateGui)
        self.pyds.unsubscribe_event(self.id_event) 
        self.app.quit()

        
if __name__ == "__main__": # pragma: no cover

    app = QtGui.QApplication(sys.argv)

    #The server push a counter
    ev1 = EventManager("test/TestDevice/TestDevice","trignumber",test1,app)
    
    sys.exit(app.exec_())

a simpler example attached.
code for the client is below :

@author: cchappet
'''
import sys,os
import time

from PyQt4 import QtCore
from PyQt4 import Qt,QtGui

import PyTango

class EventManager():
    
    def __init__(self,deviceAdr, attrAdr,app):
        #Subscribe to the counter
        self.pyds = PyTango.DeviceProxy(deviceAdr)
        self.id_event = self.pyds.subscribe_event(attrAdr, PyTango.EventType.CHANGE_EVENT, self.ReceiveTangoEvent, stateless = True)
        self.app = app
        
        #The QUIT button close the application
        self.wdButton = QtGui.QPushButton("QUIT")
        self.wdButton.clicked.connect(self.stop)
        self.wdButton.show()
        
    def ReceiveTangoEvent(self,event):
        print str(event.attr_value.value)

    #Called by the QUIT button (OK in PyTango 8.1.6, CRASH in PyTango 9.2.0)
    def stop(self):        
        self.pyds.unsubscribe_event(self.id_event) 
        self.app.quit()

        
if __name__ == "__main__": # pragma: no cover

    app = QtGui.QApplication(sys.argv)

    #The server push a counter
    ev1 = EventManager("test/TestDevice/TestDevice","trignumber",app)
    
    sys.exit(app.exec_())  

Hi Christophe,

you could check to see if the issue is solved in PyTango 9.2.3 using the pre-compiled binaries for Windows which are part of the continuous integration system on AppVeyor. Take a look at the slides 9 to 19 in this presentation:

https://indico.eli-beams.eu/event/310/session/15/contribution/52/material/slides/1.pdf

Maybe 9.2.3 solves your problem …

Cheers

Andy

Oops I was too quick. My suggestion to try out the AppVeyor Windows builds will only upgrade the Tango libraries and not PyTango.

Maybe Sebastien can help you get access to PyTango AppVeyor builds.

Sorry about raising false hopes …

Andy

Hi Christophe,

Although I don’t have a Windows version of PyTango 9.2.3, I’ve tested your code (the 2nd client version) on the linux version of PyTango 9.2.2 and it works as expected. Perhaps you could download the Windows version 9.2.2 and try it.

Regards,
Geoff.

Hi christophe,

I cannot reproduce your problem with 9.2.2 on linux neither.

Could you send the error message?

I recommend you try with 9.2.2.

I don’t see anything in the PyTango changelog that indicates your problem might be solved but since PyTango is statically linked with the tango C++ library on Windows, if you update PyTango, automatically you use the new Tango C++. So even if the problem is coming from the C++ layer, updating should make the problem disappear.

Hope it helps
Tiago

Hi Tiago and Geoff,
There is no error message, just a “python.exe stopped working”.
Do you know if there is an installer (msi, exe) for PyTango 9.2.2 on Windows because we didn’t manage to recompile.
Christophe

Hi Cristophe,

can you try this installer ?

https://ci.appveyor.com/api/buildjobs/djvtxrv064gr0ipj/artifacts/pytango-9.2.3.Win32-py2.7.msi

or the exe file
https://ci.appveyor.com/api/buildjobs/djvtxrv064gr0ipj/artifacts/pytango-9.2.3.Win32-py2.7.exe

thanks

Thanks Sébastien, the msi is working fine.
I still get a crash but with an error message :
Assertion failed: Successful WSASTARTUP not yet performed (......\src\signaler.cpp:377)

Hi, could it be related to ZMQ socket/context management?

https://stackoverflow.com/questions/19795245/zeromq-context-singleton-provided-in-a-dll-crashes-when-program-exits-vs2010

[quote=“guifre.cuni”]Hi, could it be related to ZMQ socket/context management?

https://stackoverflow.com/questions/19795245/zeromq-context-singleton-provided-in-a-dll-crashes-when-program-exits-vs2010
[/quote]

Sure looks like it. Nice catch Guifre!

Yes nice catch indeed! Is this in the C++ or Python code?

Hi, sorry for the late response. The last two messages are on the second page an I missed them.

Maybe a Tango C++ expert can confirm but my guess is that the error is in 0MQ itself.
If this is true the only fix I see is to recompile the whole chain with a version of ZMQ library which fixes the problem.

Hi,

The error seems to be in 0MQ itself indeed.
You can refer to the following libzmq issues:

So it should have been fixed in 0MQ >= 4.2.0 with this Pull Request: Merge pull request #1341 from hintjens/master · zeromq/libzmq@88ac631 · GitHub

Please avoid 0MQ 4.2.0 and 4.2.1 because there is another annoying bug (See push_change_event() - events stop being issued after some time · Issue #444 · tango-controls/cppTango · GitHub for more information).

Kind regards,
Reynald

Hi,
Sorry, too busy, or on holidays :-), to test until now …
So I have installed PyTango 9.2.3 and pyzmq 17.1.2 (so theorically zmq 4.2.5) and I still have the same problem with message :
Assertion failed: Successful WSASTARTUP not yet performed (......\src\signaler.cpp:377).

For now, the only solution I have is to keep PyTango 8.2.6.

Any further ideas ?
Regards,
Christophe

As my test on Windows, any pytango application(pytango-9.2.4 + zmq-4.2.4) using tango event will report this assertion failure on exit:

assertion failed:Successfully WSASTARTUP not yet performed[10093](..\..\..\..\src\ip.cpp:413)

but the same C++ application linked with tango dynamic library will not report this failure on exit. so this failure may relate to zmq static library on windows.

when i have time i will test c++ tango application linked with tango static library.

I’ve found an issue on ZMQ GitHub about this problem.

The solution is:

Any suggestions how can we use it in PyTango clients?