Show More
@@ -16,3 +16,8 b'' | |||
|
16 | 16 | # from .remotefunction import * |
|
17 | 17 | # from .view import * |
|
18 | 18 | |
|
19 | import zmq | |
|
20 | ||
|
21 | if zmq.__version__ < '2.1.3': | |
|
22 | raise ImportError("IPython.zmq.parallel requires pyzmq/0MQ >= 2.1.3, you appear to have %s"%zmq.__version__) | |
|
23 |
@@ -284,7 +284,7 b' class Client(HasTraits):' | |||
|
284 | 284 | ): |
|
285 | 285 | super(Client, self).__init__(debug=debug, profile=profile) |
|
286 | 286 | if context is None: |
|
287 | context = zmq.Context() | |
|
287 | context = zmq.Context.instance() | |
|
288 | 288 | self._context = context |
|
289 | 289 | |
|
290 | 290 | |
@@ -976,6 +976,10 b' class Client(HasTraits):' | |||
|
976 | 976 | returns actual result(s) of f(*args, **kwargs) |
|
977 | 977 | if multiple targets: |
|
978 | 978 | list of results, matching `targets` |
|
979 | track : bool | |
|
980 | whether to track non-copying sends. | |
|
981 | [default False] | |
|
982 | ||
|
979 | 983 | targets : int,list of ints, 'all', None |
|
980 | 984 | Specify the destination of the job. |
|
981 | 985 | if None: |
@@ -986,34 +990,37 b' class Client(HasTraits):' | |||
|
986 | 990 | Run on each specified engine |
|
987 | 991 | if int: |
|
988 | 992 | Run on single engine |
|
989 | ||
|
993 | Note: | |
|
994 | that if `balanced=True`, and `targets` is specified, | |
|
995 | then the load-balancing will be limited to balancing | |
|
996 | among `targets`. | |
|
997 | ||
|
990 | 998 | balanced : bool, default None |
|
991 | 999 | whether to load-balance. This will default to True |
|
992 | 1000 | if targets is unspecified, or False if targets is specified. |
|
993 | ||
|
994 | The following arguments are only used when balanced is True: | |
|
1001 | ||
|
1002 | If `balanced` and `targets` are both specified, the task will | |
|
1003 | be assigne to *one* of the targets by the scheduler. | |
|
1004 | ||
|
1005 | The following arguments are only used when balanced is True: | |
|
1006 | ||
|
995 | 1007 | after : Dependency or collection of msg_ids |
|
996 | 1008 | Only for load-balanced execution (targets=None) |
|
997 | 1009 | Specify a list of msg_ids as a time-based dependency. |
|
998 | 1010 | This job will only be run *after* the dependencies |
|
999 | 1011 | have been met. |
|
1000 | ||
|
1012 | ||
|
1001 | 1013 | follow : Dependency or collection of msg_ids |
|
1002 | 1014 | Only for load-balanced execution (targets=None) |
|
1003 | 1015 | Specify a list of msg_ids as a location-based dependency. |
|
1004 | 1016 | This job will only be run on an engine where this dependency |
|
1005 | 1017 | is met. |
|
1006 | ||
|
1018 | ||
|
1007 | 1019 | timeout : float/int or None |
|
1008 | 1020 | Only for load-balanced execution (targets=None) |
|
1009 | 1021 | Specify an amount of time (in seconds) for the scheduler to |
|
1010 | 1022 | wait for dependencies to be met before failing with a |
|
1011 | 1023 | DependencyTimeout. |
|
1012 | track : bool | |
|
1013 | whether to track non-copying sends. | |
|
1014 | [default False] | |
|
1015 | ||
|
1016 | after,follow,timeout only used if `balanced=True`. | |
|
1017 | 1024 | |
|
1018 | 1025 | Returns |
|
1019 | 1026 | ------- |
@@ -1022,7 +1029,7 b' class Client(HasTraits):' | |||
|
1022 | 1029 | return AsyncResult wrapping msg_ids |
|
1023 | 1030 | output of AsyncResult.get() is identical to that of `apply(...block=True)` |
|
1024 | 1031 | else: |
|
1025 | if single target: | |
|
1032 | if single target (or balanced): | |
|
1026 | 1033 | return result of `f(*args, **kwargs)` |
|
1027 | 1034 | else: |
|
1028 | 1035 | return list of results, matching `targets` |
@@ -69,8 +69,9 b' class ClusterTestCase(BaseZMQTestCase):' | |||
|
69 | 69 | def connect_client(self): |
|
70 | 70 | """connect a client with my Context, and track its sockets for cleanup""" |
|
71 | 71 | c = Client(profile='iptest',context=self.context) |
|
72 | for name in filter(lambda n:n.endswith('socket'), dir(c)): | |
|
73 | self.sockets.append(getattr(c, name)) | |
|
72 | ||
|
73 | # for name in filter(lambda n:n.endswith('socket'), dir(c)): | |
|
74 | # self.sockets.append(getattr(c, name)) | |
|
74 | 75 | return c |
|
75 | 76 | |
|
76 | 77 | def assertRaisesRemote(self, etype, f, *args, **kwargs): |
@@ -100,6 +101,6 b' class ClusterTestCase(BaseZMQTestCase):' | |||
|
100 | 101 | BaseZMQTestCase.tearDown(self) |
|
101 | 102 | # this will be superfluous when pyzmq merges PR #88 |
|
102 | 103 | self.context.term() |
|
103 | print tempfile.TemporaryFile().fileno(), | |
|
104 | sys.stdout.flush() | |
|
104 | # print tempfile.TemporaryFile().fileno(), | |
|
105 | # sys.stdout.flush() | |
|
105 | 106 | No newline at end of file |
@@ -1,7 +1,6 b'' | |||
|
1 | 1 | import time |
|
2 | 2 | from tempfile import mktemp |
|
3 | 3 | |
|
4 | import nose.tools as nt | |
|
5 | 4 | import zmq |
|
6 | 5 | |
|
7 | 6 | from IPython.zmq.parallel import client as clientmod |
@@ -65,7 +64,7 b' class TestClient(ClusterTestCase):' | |||
|
65 | 64 | v = self.client[-1] |
|
66 | 65 | self.assert_(isinstance(v, DirectView)) |
|
67 | 66 | self.assertEquals(v.targets, targets[-1]) |
|
68 |
|
|
|
67 | self.assertRaises(TypeError, lambda : self.client[None]) | |
|
69 | 68 | |
|
70 | 69 | def test_view_cache(self): |
|
71 | 70 | """test that multiple view requests return the same object""" |
@@ -179,6 +178,7 b' class TestClient(ClusterTestCase):' | |||
|
179 | 178 | """test getting results from the Hub.""" |
|
180 | 179 | c = clientmod.Client(profile='iptest') |
|
181 | 180 | self.add_engines(1) |
|
181 | t = c.ids[-1] | |
|
182 | 182 | ar = c.apply(wait, (1,), block=False, targets=t) |
|
183 | 183 | # give the monitor time to notice the message |
|
184 | 184 | time.sleep(.25) |
@@ -2,8 +2,6 b'' | |||
|
2 | 2 | |
|
3 | 3 | from unittest import TestCase |
|
4 | 4 | |
|
5 | import nose.tools as nt | |
|
6 | ||
|
7 | 5 | from IPython.testing.parametric import parametric |
|
8 | 6 | from IPython.utils import newserialized as ns |
|
9 | 7 | from IPython.utils.pickleutil import can, uncan, CannedObject, CannedFunction |
@@ -14,12 +12,12 b' class CanningTestCase(TestCase):' | |||
|
14 | 12 | def test_canning(self): |
|
15 | 13 | d = dict(a=5,b=6) |
|
16 | 14 | cd = can(d) |
|
17 |
|
|
|
15 | self.assertTrue(isinstance(cd, dict)) | |
|
18 | 16 | |
|
19 | 17 | def test_canned_function(self): |
|
20 | 18 | f = lambda : 7 |
|
21 | 19 | cf = can(f) |
|
22 |
|
|
|
20 | self.assertTrue(isinstance(cf, CannedFunction)) | |
|
23 | 21 | |
|
24 | 22 | @parametric |
|
25 | 23 | def test_can_roundtrip(cls): |
@@ -32,17 +30,17 b' class CanningTestCase(TestCase):' | |||
|
32 | 30 | return map(cls.run_roundtrip, objs) |
|
33 | 31 | |
|
34 | 32 | @classmethod |
|
35 |
def run_roundtrip( |
|
|
33 | def run_roundtrip(self, obj): | |
|
36 | 34 | o = uncan(can(obj)) |
|
37 | nt.assert_equals(obj, o) | |
|
35 | assert o == obj, "failed assertion: %r == %r"%(o,obj) | |
|
38 | 36 | |
|
39 | 37 | def test_serialized_interfaces(self): |
|
40 | 38 | |
|
41 | 39 | us = {'a':10, 'b':range(10)} |
|
42 | 40 | s = ns.serialize(us) |
|
43 | 41 | uus = ns.unserialize(s) |
|
44 |
|
|
|
45 |
|
|
|
42 | self.assertTrue(isinstance(s, ns.SerializeIt)) | |
|
43 | self.assertEquals(uus, us) | |
|
46 | 44 | |
|
47 | 45 | def test_pickle_serialized(self): |
|
48 | 46 | obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L} |
@@ -51,16 +49,16 b' class CanningTestCase(TestCase):' | |||
|
51 | 49 | firstData = originalSer.getData() |
|
52 | 50 | firstTD = originalSer.getTypeDescriptor() |
|
53 | 51 | firstMD = originalSer.getMetadata() |
|
54 |
|
|
|
55 |
|
|
|
52 | self.assertEquals(firstTD, 'pickle') | |
|
53 | self.assertEquals(firstMD, {}) | |
|
56 | 54 | unSerialized = ns.UnSerializeIt(originalSer) |
|
57 | 55 | secondObj = unSerialized.getObject() |
|
58 | 56 | for k, v in secondObj.iteritems(): |
|
59 |
|
|
|
57 | self.assertEquals(obj[k], v) | |
|
60 | 58 | secondSer = ns.SerializeIt(ns.UnSerialized(secondObj)) |
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
59 | self.assertEquals(firstData, secondSer.getData()) | |
|
60 | self.assertEquals(firstTD, secondSer.getTypeDescriptor() ) | |
|
61 | self.assertEquals(firstMD, secondSer.getMetadata()) | |
|
64 | 62 | |
|
65 | 63 | @skip_without('numpy') |
|
66 | 64 | def test_ndarray_serialized(self): |
@@ -69,21 +67,21 b' class CanningTestCase(TestCase):' | |||
|
69 | 67 | unSer1 = ns.UnSerialized(a) |
|
70 | 68 | ser1 = ns.SerializeIt(unSer1) |
|
71 | 69 | td = ser1.getTypeDescriptor() |
|
72 |
|
|
|
70 | self.assertEquals(td, 'ndarray') | |
|
73 | 71 | md = ser1.getMetadata() |
|
74 |
|
|
|
75 |
|
|
|
72 | self.assertEquals(md['shape'], a.shape) | |
|
73 | self.assertEquals(md['dtype'], a.dtype.str) | |
|
76 | 74 | buff = ser1.getData() |
|
77 |
|
|
|
75 | self.assertEquals(buff, numpy.getbuffer(a)) | |
|
78 | 76 | s = ns.Serialized(buff, td, md) |
|
79 | 77 | final = ns.unserialize(s) |
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
78 | self.assertEquals(numpy.getbuffer(a), numpy.getbuffer(final)) | |
|
79 | self.assertTrue((a==final).all()) | |
|
80 | self.assertEquals(a.dtype.str, final.dtype.str) | |
|
81 | self.assertEquals(a.shape, final.shape) | |
|
84 | 82 | # test non-copying: |
|
85 | 83 | a[2] = 1e9 |
|
86 |
|
|
|
84 | self.assertTrue((a==final).all()) | |
|
87 | 85 | |
|
88 | 86 | |
|
89 | 87 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now