Skip to content

Commit

Permalink
Fix transport references: device becomes owner of the list of transports
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagocoutinho committed Feb 9, 2021
1 parent 52e21fa commit 54f3dd7
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions sinstruments/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,23 +316,12 @@ def __init__(self, name, server=None, **kwargs):
self.server = server
self.newline = kwargs.pop('newline', self.newline)
self._log = logging.getLogger("{0}.{1}".format(_log.name, name))
self.__transports = weakref.WeakKeyDictionary()
self.transports = []
self.props = kwargs

def get_protocol(self, channel, transport):
return self.protocol(self, channel, transport)

@property
def transports(self):
"""the list of registered transports"""
return self.__transports.keys()

@transports.setter
def transports(self, transports):
self.__transports.clear()
for transport in transports:
self.__transports[transport] = None

def on_connection(self, transport, conn):
pass

Expand Down Expand Up @@ -400,9 +389,9 @@ def create_device(self, device_info):
assert name not in self.devices
self._log.info("Creating device %s (%r)", name, klass_name)
device_info["server"] = self
device, transports = create_device(device_info, self.registry)
device = create_device(device_info, self.registry)
self.devices[name] = device
return device, transports
return device

def get_device_by_name(self, name):
return self.devices[name]
Expand Down Expand Up @@ -461,7 +450,7 @@ def create_device(device_info, registry):
iklass = SerialServer
transports.append(iklass(device.name, device.get_protocol, **ikwargs))
device.transports = transports
return device, transports
return device


def load_device_registry():
Expand Down Expand Up @@ -519,7 +508,6 @@ def main():
logging.basicConfig(format=fmt, level=level)
config = parse_config_file(args.config_file)
server = create_server_from_config(config)

try:
server.serve_forever()
except KeyboardInterrupt:
Expand Down

0 comments on commit 54f3dd7

Please sign in to comment.