Skip to content

Commit ccc2d9c

Browse files
committed
device_server.serve_devices: copy devices to prevent change on caller (#211)
This commit has serve_devices make a deepcopy of the devices argument so that in case we need to make changes to it, we don't modify the stuff in the caller. This commit reverts ef280c3 which was another fix for this issue. The way we support floating devices requires that we inject the index value on the device configuration. However, we don't want that to propagate to the caller which may be reusing that configuration (and it kinda does it when device configuration is not specified see discussion on #212).
1 parent 7e21484 commit ccc2d9c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

microscope/device_server.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"""
3636

3737
import argparse
38+
import copy
3839
import importlib.machinery
3940
import importlib.util
4041
import logging
@@ -81,7 +82,7 @@ def device(
8182
cls: typing.Callable,
8283
host: str,
8384
port: int,
84-
conf: typing.Mapping[str, typing.Any] = None,
85+
conf: typing.Mapping[str, typing.Any] = {},
8586
uid: typing.Optional[str] = None,
8687
):
8788
"""Define devices and where to serve them.
@@ -119,8 +120,6 @@ def construct_devices() -> typing.Dict[str, Device]:
119120
]
120121
121122
"""
122-
if conf is None:
123-
conf = {}
124123
if not callable(cls):
125124
raise TypeError("cls must be a callable")
126125
elif isinstance(cls, type):
@@ -392,6 +391,12 @@ def run(self):
392391

393392

394393
def serve_devices(devices, options: DeviceServerOptions, exit_event=None):
394+
# We make changes to `devices` (would be great if we didn't had
395+
# to) so make a a copy of it because we don't want to make those
396+
# changes on the caller. See original issue on #211 and PRs #212
397+
# and #217 (most discussion happens on #212).
398+
devices = copy.deepcopy(devices)
399+
395400
root_logger = logging.getLogger()
396401

397402
log_handler = RotatingFileHandler("__MAIN__.log")

0 commit comments

Comments
 (0)