diff --git a/artiq/protocols/sync_struct.py b/artiq/protocols/sync_struct.py index 95b390faa..00979ac91 100644 --- a/artiq/protocols/sync_struct.py +++ b/artiq/protocols/sync_struct.py @@ -13,6 +13,7 @@ immutable types. Lists and dicts can be nested arbitrarily. import asyncio from operator import getitem +from functools import partial from artiq.protocols import pyon from artiq.protocols.asyncio_server import AsyncioServer @@ -154,9 +155,9 @@ class Notifier: """ self._backing_struct.append(x) if self.root.publish is not None: - self.root.publish(self.root, {"action": "append", - "path": self._path, - "x": x}) + self.root.publish({"action": "append", + "path": self._path, + "x": x}) def insert(self, i, x): """Insert an element into a list. @@ -164,9 +165,9 @@ class Notifier: """ self._backing_struct.insert(i, x) if self.root.publish is not None: - self.root.publish(self.root, {"action": "insert", - "path": self._path, - "i": i, "x": x}) + self.root.publish({"action": "insert", + "path": self._path, + "i": i, "x": x}) def pop(self, i=-1): """Pop an element from a list. The returned element is not @@ -176,25 +177,25 @@ class Notifier: """ r = self._backing_struct.pop(i) if self.root.publish is not None: - self.root.publish(self.root, {"action": "pop", - "path": self._path, - "i": i}) + self.root.publish({"action": "pop", + "path": self._path, + "i": i}) return r def __setitem__(self, key, value): self._backing_struct.__setitem__(key, value) if self.root.publish is not None: - self.root.publish(self.root, {"action": "setitem", - "path": self._path, - "key": key, - "value": value}) + self.root.publish({"action": "setitem", + "path": self._path, + "key": key, + "value": value}) def __delitem__(self, key): self._backing_struct.__delitem__(key) if self.root.publish is not None: - self.root.publish(self.root, {"action": "delitem", - "path": self._path, - "key": key}) + self.root.publish({"action": "delitem", + "path": self._path, + "key": key}) def __getitem__(self, key): item = getitem(self._backing_struct, key) @@ -217,7 +218,7 @@ class Publisher(AsyncioServer): self._notifier_names = {id(v): k for k, v in notifiers.items()} for notifier in notifiers.values(): - notifier.publish = self.publish + notifier.publish = partial(self.publish, notifier) @asyncio.coroutine def _handle_connection_cr(self, reader, writer): @@ -256,8 +257,8 @@ class Publisher(AsyncioServer): finally: writer.close() - def publish(self, notifier, obj): - line = pyon.encode(obj) + "\n" + def publish(self, notifier, mod): + line = pyon.encode(mod) + "\n" line = line.encode() notifier_name = self._notifier_names[id(notifier)] for recipient in self._recipients[notifier_name]: diff --git a/artiq/test/scheduler.py b/artiq/test/scheduler.py index a70342486..53dd7c6f3 100644 --- a/artiq/test/scheduler.py +++ b/artiq/test/scheduler.py @@ -67,7 +67,7 @@ class SchedulerCase(unittest.TestCase): expect = _get_basic_steps(1, expid) done = asyncio.Event() expect_idx = 0 - def notify(notifier, mod): + def notify(mod): nonlocal expect_idx self.assertEqual(mod, expect[expect_idx]) expect_idx += 1 @@ -104,7 +104,7 @@ class SchedulerCase(unittest.TestCase): background_running = asyncio.Event() done = asyncio.Event() expect_idx = 0 - def notify(notifier, mod): + def notify(mod): nonlocal expect_idx if mod == {"path": [0], "value": "running", @@ -138,7 +138,7 @@ class SchedulerCase(unittest.TestCase): first_preparing = asyncio.Event() done = asyncio.Event() expect_idx = 0 - def notify(notifier, mod): + def notify(mod): nonlocal expect_idx if mod == {"path": [0], "value": "preparing",