[qudi-dev] Qt Signal in PyQt5 and in Qudi

  • From: Alexander Stark <alexander.stark@xxxxxxxxxx>
  • To: qudi-dev@xxxxxxxxxxxxx
  • Date: Tue, 11 Apr 2017 23:25:28 +0200

Hi Qudi developer,

I would like to make an important annotation concerning the usage of Qt Signals <http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html#PyQt5.QtCore.pyqtSignal> within Qudi.

As we moved to PyQt5 being the new default GUI toolkit and also recently to Python 3.6.x there are appearing some considerable issue if the signal signature is not correct during runtime. Since Pyton 3.5 and PyQt 5.3, <None> was used as the default overload argument of the emit method of a signal object, i.e. if you are performing something like

    a_signal.emit('test')

then it was also possible to make

    a_signal.emit(None)

That means <None> is the default overload for the slot signature of the signal.

This has changed now and it is not possible to use that any more. Here is one of the pyqt5 announcements <http://pyqt.sourceforge.net/Docs/PyQt5/incompatibilities.html#pyqt-v5-3> and an issue <https://github.com/pytest-dev/pytest-qt/issues/69> connected to that.

That means do not use the <None> assignment as a default value for the object, which you want to pass to the emit method of a signal. This will cause in the best case a type error exception, but can also lead to a complete crash of Qudi (if signals are passed e.g. along threads, seeissue 182 <https://github.com/Ulm-IQO/qudi/issues/182>), which could be hard to track.

To clarify that, a small example:
A signal and two class variables are defined as

...
class test_class(...)
    signal_a = QtCore.Signal(str, np.ndarray)

    name = None             # Do not do that
    data_array = None    # Do not do that
    ...
    def some_method(self):
        self.signal_a.emit(name, data_array)

Here 'name' and 'data_array' are initially set to None, because their value should be changed later. But if one of the class variable values does not change before the method some_method is executed, then you will obtain an error. Therefore change the initial values according to the type of the signal signature:

    name = ''                             # default string
    data_array = np.array([])   # default array

I know that this was a handy way of specifying not-set variables, but if you want to use the variable in signals then do not change their types.

I am going to address this issue in the 'signal_signature <https://github.com/Ulm-IQO/qudi/tree/signal_signature>' branch. If you find more of this problems in Qudi, then please report that in issue 182 <https://github.com/Ulm-IQO/qudi/issues/182>.

Best,
Alex


--
Alexander Stark
Institut für Quantenoptik
N25 / 4107
Universität Ulm
Albert-Einstein-Allee 11
D-89081 Ulm

Tel: +49731-50-23755
E-Mail: alexander.stark@xxxxxxxxxx
http://www.quantenoptik.de

Other related posts:

  • » [qudi-dev] Qt Signal in PyQt5 and in Qudi - Alexander Stark