From d9c4c972a3cc79c2cd2672ed957f316fc7b8781a Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Fri, 3 Jun 2016 11:18:59 +0100 Subject: [PATCH] Add spawn to process --- malcolm/core/process.py | 7 +++++++ tests/test_core/test_process.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/malcolm/core/process.py b/malcolm/core/process.py index eb479e892..775f6db13 100644 --- a/malcolm/core/process.py +++ b/malcolm/core/process.py @@ -84,3 +84,10 @@ def create_queue(self): """ return self.sync_factory.create_queue() + + def spawn(self, function, *args, **kwargs): + """Calls SyncFactory.spawn()""" + spawned = self.sync_factory.spawn(function, *args, **kwargs) + self._other_spawned.append(spawned) + return spawned + diff --git a/tests/test_core/test_process.py b/tests/test_core/test_process.py index 3b3078c75..4b157b199 100644 --- a/tests/test_core/test_process.py +++ b/tests/test_core/test_process.py @@ -51,5 +51,13 @@ def test_error(self): p.log_exception.assert_called_once_with("Exception while handling %s", "") + def test_spawned_adds_to_other_spawned(self): + s = MagicMock() + p = Process("proc", s) + spawned = p.spawn(callable, "fred", a=4) + self.assertEqual(spawned, s.spawn.return_value) + self.assertEqual(p._other_spawned, [spawned]) + s.spawn.assert_called_once_with(callable, "fred", a=4) + if __name__ == "__main__": unittest.main(verbosity=2)