Short question on pytango Device.init_device() and Device.delete_device()

Hello there,
after some time of working with the basic functionalities of pytango and its high level server API I found myself frequently using init_device() to create instance variables and got curious whether this is the right way to handle things. Whenever I create one my IDE complains, that it should not be declared outside of __init__() (which to my understanding should not/ does not need to be accesed by me at all, right?) which makes me wonder whether these are now any different from instance variables created in __init__() (as done in regular python usage).

A little recent example of mine would be a server in need of a background thread. Currently my thread is created and started in init_device() and a stop event is triggered in delete_device(). Is this the "correct" way to use these two methods or am i overseeing some unforeseen consequences here?
Hi larpsid,

I would say your logic is correct.

You can initialize the variables to None in __init__ to prevent IDE warnings or tag the init_device with #noqa so the IDE does not complain (I prefer the second):


class MyDevice(Device):

def init_device(self):
super().init_device()
self.task = threading.Thread(target=…) # noqa

def delete_device(self):
self.stop_task.set()
self.task.join()
self.task = None
 
Register or login to create to post a reply.