Skip to content

Commit e3488cb

Browse files
committed
DeviceServer: new clone method to help restart server
This means that keep_alive() does not need to be accessing the internal DeviceServer attributes to restart a device server.
1 parent 4ebf36d commit e3488cb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

microscope/deviceserver.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ def __init__(self, device_def, id_to_host, id_to_port, count=0,
117117
# Some SDKs need an index to access more than one device.
118118
self.count = count
119119

120+
def clone(self):
121+
"""Create new instance with same settings.
122+
123+
This is useful to restart a device server.
124+
"""
125+
return DeviceServer(self._device_def, self._id_to_host,
126+
self._id_to_port, exit_event=self.exit_event,
127+
count=self.count)
128+
120129
def run(self):
121130
logger = logging.getLogger(self._device_def['cls'].__name__)
122131
if __debug__:
@@ -268,11 +277,7 @@ def keep_alive():
268277
" exitcode %s. Restarting...")
269278
% (s.pid, s.exitcode))
270279
servers.remove(s)
271-
servers.append(DeviceServer(s._device_def,
272-
s._id_to_host,
273-
s._id_to_port,
274-
exit_event=exit_event,
275-
count=s.count))
280+
servers.append(s.clone())
276281

277282
try:
278283
s.join(30)

0 commit comments

Comments
 (0)