diff --git a/IPython/zmq/parallel/client.py b/IPython/zmq/parallel/client.py index bceceb9..fcd3cfe 100644 --- a/IPython/zmq/parallel/client.py +++ b/IPython/zmq/parallel/client.py @@ -378,7 +378,8 @@ class Client(HasTraits): def ids(self): """Always up-to-date ids property.""" self._flush_notifications() - return self._ids + # always copy: + return list(self._ids) def close(self): if self._closed: @@ -878,8 +879,10 @@ class Client(HasTraits): default: self.block """ - with open(filename, 'rb') as f: - code = f.read() + with open(filename, 'r') as f: + # add newline in case of trailing indented whitespace + # which will cause SyntaxError + code = f.read()+'\n' return self.execute(code, targets=targets, block=block) def _maybe_raise(self, result): diff --git a/IPython/zmq/parallel/tests/test_client.py b/IPython/zmq/parallel/tests/test_client.py index 21ff03b..27f2863 100644 --- a/IPython/zmq/parallel/tests/test_client.py +++ b/IPython/zmq/parallel/tests/test_client.py @@ -1,4 +1,5 @@ import time +from tempfile import mktemp import nose.tools as nt @@ -162,4 +163,25 @@ class TestClient(ClusterTestCase): self.assertEquals(ahr.get(), ar.get()) ar2 = self.client.get_result(ar.msg_ids) self.assertFalse(isinstance(ar2, AsyncHubResult)) + + def test_ids_list(self): + """test client.ids""" + self.add_engines(2) + ids = self.client.ids + self.assertEquals(ids, self.client._ids) + self.assertFalse(ids is self.client._ids) + ids.remove(ids[-1]) + self.assertNotEquals(ids, self.client._ids) + + def test_arun_newline(self): + """test that run appends newline to files""" + tmpfile = mktemp() + with open(tmpfile, 'w') as f: + f.write("""def g(): + return 5 + """) + v = self.client[-1] + v.run(tmpfile, block=True) + self.assertEquals(v.apply_sync_bound(lambda : g()), 5) + \ No newline at end of file