3636
3737import Pyro4
3838
39- from microscope .devices import FloatingDeviceMixin
39+ import microscope .devices
4040
4141# Pyro configuration. Use pickle because it can serialize numpy ndarrays.
4242Pyro4 .config .SERIALIZERS_ACCEPTED .add ('pickle' )
@@ -147,7 +147,7 @@ def run(self):
147147 time .sleep (5 )
148148 else :
149149 break
150- if (isinstance (self ._device , FloatingDeviceMixin )
150+ if (isinstance (self ._device , microscope . devices . FloatingDeviceMixin )
151151 and len (self ._id_to_host ) > 1 ):
152152 uid = str (self ._device .get_id ())
153153 if uid not in self ._id_to_host or uid not in self ._id_to_port :
@@ -168,11 +168,33 @@ def run(self):
168168 # Run the Pyro daemon in a separate thread so that we can do
169169 # clean shutdown under Windows.
170170 pyro_daemon .register (self ._device , type (self ._device ).__name__ )
171+ if isinstance (self ._device , microscope .devices .ControllerDevice ):
172+ # AUTOPROXY should be enabled by default. If we find it
173+ # disabled, there must be a reason why, so raise an error
174+ # instead of silently enabling it.
175+ if not Pyro4 .config .AUTOPROXY :
176+ raise RuntimeError ('serving of a ControllerDevice requires'
177+ ' Pyro4 AUTOPROXY option enabled' )
178+
179+ # Autoproxy does not work with marshal serializer.
180+ Pyro4 .config .SERIALIZERS_ACCEPTED .discard ('marshal' )
181+
182+ for sub_device in self ._device .devices .values ():
183+ # FIXME: by the time we do this the device has already
184+ # been created and initialised and that won't be
185+ # logged. We need to rethink having a log per device
186+ # (issue #110)
187+ sub_device ._logger .addHandler (stderr_handler )
188+ sub_device ._logger .addHandler (log_handler )
189+ sub_device ._logger .addFilter (Filter ())
190+ # This requires
191+ pyro_daemon .register (sub_device )
192+
171193 pyro_thread = Thread (target = pyro_daemon .requestLoop )
172194 pyro_thread .daemon = True
173195 pyro_thread .start ()
174196 logger .info ('Serving %s' % pyro_daemon .uriFor (self ._device ))
175- if isinstance (self ._device , FloatingDeviceMixin ):
197+ if isinstance (self ._device , microscope . devices . FloatingDeviceMixin ):
176198 logger .info ('Device UID on port %s is %s' % (port , self ._device .get_id ()))
177199 # Wait for termination event. We should just be able to call
178200 # wait() on the exit_event, but this causes issues with locks
@@ -239,7 +261,7 @@ def term_func(sig, frame):
239261 # Keep track of how many of these classes we have set up.
240262 # Some SDKs need this information to index devices.
241263 count = 0
242- if issubclass (cls , FloatingDeviceMixin ):
264+ if issubclass (cls , microscope . devices . FloatingDeviceMixin ):
243265 # Need to provide maps of uid to host and port.
244266 uid_to_host = {}
245267 uid_to_port = {}
0 commit comments