LabPy / lantz

Lantz is an automation and instrumentation toolkit with a clean, well-designed and consistent interface. It provides a core of commonly used functionalities for building applications that communicate with scientific instruments allowing rapid application prototyping, development and testing. Lantz benefits from Python’s extensive library flexibility as a glue language to wrap existing drivers and DLLs.
http://lantz.readthedocs.org/
Other
135 stars 65 forks source link

Driver refresh() fails with DictFeats #69

Open Duncanla opened 8 years ago

Duncanla commented 8 years ago

This error occurs when trying to refresh() a driver with DictFeats:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/site-packages/lantz/feat.py", line 487, in __repr__
    return repr(self.df.value[self.instance])
  File "/usr/lib/python3.5/weakref.py", line 365, in __getitem__
    return self.data[ref(key)]
KeyError: <weakref at 0x7f6d12c9fa98; to 'DriverName' at 0x7f6d202fc558>

If I initialize all of the DictFeats (simply by reading from at least one key for each one), then everything works fine.

This modification to _DictFeatAccesor works around the problem, although I'm not sure if it is a good solution:

def __repr__(self):
    if self.instance in self.df.value.keys():
        return repr(self.df.value[self.instance])
    else:
        return ""