taurus-org / taurus

Moved to https://gitlab.com/taurus-org/taurus
http://taurus-scada.org
43 stars 46 forks source link

Import taurus in PyTango DS causes that delete_device is not called at shutdown #982

Open reszelaz opened 5 years ago

reszelaz commented 5 years ago

Not sure if this is a problem in Taurus or PyTango. But if I import taurus in PyTango DS this causes that the delete_device method is not called at the DS shutdown. This does not happen with python 2 but happens with python 3.

To reproduce:

  1. Copy the following snippet in PyDsExp.py file:
import sys

import PyTango
import taurus

class PyDsExpClass(PyTango.DeviceClass):

    def __init__(self, name):
        PyTango.DeviceClass.__init__(self, name)
        self.set_type("TestDevice")

class PyDsExp(PyTango.Device_4Impl):

    def __init__(self,cl,name):
        PyTango.Device_4Impl.__init__(self, cl, name)
        PyDsExp.init_device(self)

    def init_device(self):
        self.set_state(PyTango.DevState.ON)

    def delete_device(self):
        print("delete_device")

if __name__ == '__main__':
    util = PyTango.Util(sys.argv)
    util.add_class(PyDsExpClass, PyDsExp)

    U = PyTango.Util.instance()
    U.server_init()
    U.server_run()
  1. Define PyDsExp DS instance with one device:

    tango_admin --add-server PyDsExp/test PyDsExp test/pydsexp/1

    On Debian tango_admin is installed in /usr/lib/tango.

  2. Run DS:

    python3 PyDsExp.py test
  3. After the DS is ready press Ctrl + C.

Then, you won't observe "delete_device" print. When you run it with python 2 you can see it.

cmft commented 5 years ago

The problem is caused by:

from pint import UnitRegistry
UR = UnitRegistry()

in taurus.core.units module

cmft commented 5 years ago

The problem can be simplified importing just pint

mrosanes commented 5 years ago

I don't know why, but in my machine debain9 I cannot reproduce the problem with python3 and PyTango version 9.2.5. The print 'delete_device' appears correctly.

However in python2 and PyTango version 9.2.0 the print is not there; the delete_device method is not called in python2 in my case.

cmft commented 5 years ago

Now, I reproduce the problem in my stretch machine with both Py2 and Py3. I can not reproduce the error with the taurus Py3 conda env. (using tango 9.3.1)

Pint is 0.9 version in all case.