Skip to content

Commit 2ace980

Browse files
author
Kristoffel Pirard
committed
prior: fix AttributeError for bad connections
When constructing a ProScanIII object on a port that does not contain a prior controller, the _devices member is not defined. This causes the __del__ operation of the object to fail, because it will end up in the base class' __del__, which requires the `devices` property, which requires the `_devices` member to be present. Conceptually, the base class requires the implementation to be a valid object. One may also argue that the object is not allowed to be construted at all if not connected to a proper device; that would be an alternative fix.
1 parent 2c282da commit 2ace980

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

microscope/controllers/prior.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,17 @@ class ProScanIII(microscope.abc.Controller):
211211
def __init__(
212212
self, port: str, baudrate: int = 9600, timeout: float = 0.5, **kwargs
213213
) -> None:
214-
super().__init__(**kwargs)
215-
self._conn = _ProScanIIIConnection(port, baudrate, timeout)
216214
self._devices: Mapping[str, microscope.abc.Device] = {}
217215

218-
# Can have up to three filter wheels, numbered 1 to 3.
219-
for number in range(1, 4):
220-
if self._conn.has_filterwheel(number):
221-
key = "filter %d" % number
222-
self._devices[key] = _ProScanIIIFilterWheel(self._conn, number)
216+
self._conn = _ProScanIIIConnection(port, baudrate, timeout)
217+
218+
self._devices = {
219+
"filter %d" % number: _ProScanIIIFilterWheel(self._conn, number)
220+
for number in range(1, 4) # Can have up to three filter wheels, numbered 1 to 3.
221+
if self._conn.has_filterwheel(number)
222+
}
223+
224+
super().__init__(**kwargs)
223225

224226
@property
225227
def devices(self) -> Mapping[str, microscope.abc.Device]:

0 commit comments

Comments
 (0)