##// END OF EJS Templates
Minor work on kernelmanager....
Brian Granger -
Show More
@@ -27,7 +27,7 b' from unittest import TestCase'
27 from IPython.utils.traitlets import (
27 from IPython.utils.traitlets import (
28 HasTraits, MetaHasTraits, TraitType, Any,
28 HasTraits, MetaHasTraits, TraitType, Any,
29 Int, Long, Float, Complex, Str, Unicode, TraitError,
29 Int, Long, Float, Complex, Str, Unicode, TraitError,
30 Undefined, Type, This, Instance
30 Undefined, Type, This, Instance, TCPAddress
31 )
31 )
32
32
33
33
@@ -684,3 +684,16 b' class TestUnicode(TraitTestBase):'
684 '-10.1', '', u'', 'string', u'string', ]
684 '-10.1', '', u'', 'string', u'string', ]
685 _bad_values = [10, -10, 10L, -10L, 10.1, -10.1, 1j,
685 _bad_values = [10, -10, 10L, -10L, 10.1, -10.1, 1j,
686 [10], ['ten'], [u'ten'], {'ten': 10},(10,), None]
686 [10], ['ten'], [u'ten'], {'ten': 10},(10,), None]
687
688
689 class TCPAddressTrait(HasTraits):
690
691 value = TCPAddress()
692
693 class TestTCPAddress(TraitTestBase):
694
695 obj = TCPAddressTrait()
696
697 _default_value = ('127.0.0.1',0)
698 _good_values = [('localhost',0),('192.168.0.1',1000),('www.google.com',80)]
699 _bad_values = [(0,0),('localhost',10.0),('localhost',-1)]
@@ -230,8 +230,7 b' class TraitType(object):'
230
230
231 def get_default_value(self):
231 def get_default_value(self):
232 """Create a new instance of the default value."""
232 """Create a new instance of the default value."""
233 dv = self.default_value
233 return self.default_value
234 return dv
235
234
236 def instance_init(self, obj):
235 def instance_init(self, obj):
237 """This is called by :meth:`HasTraits.__new__` to finish init'ing.
236 """This is called by :meth:`HasTraits.__new__` to finish init'ing.
@@ -798,7 +797,6 b' class Any(TraitType):'
798 class Int(TraitType):
797 class Int(TraitType):
799 """A integer trait."""
798 """A integer trait."""
800
799
801 evaluate = int
802 default_value = 0
800 default_value = 0
803 info_text = 'an integer'
801 info_text = 'an integer'
804
802
@@ -820,7 +818,6 b' class CInt(Int):'
820 class Long(TraitType):
818 class Long(TraitType):
821 """A long integer trait."""
819 """A long integer trait."""
822
820
823 evaluate = long
824 default_value = 0L
821 default_value = 0L
825 info_text = 'a long'
822 info_text = 'a long'
826
823
@@ -845,7 +842,6 b' class CLong(Long):'
845 class Float(TraitType):
842 class Float(TraitType):
846 """A float trait."""
843 """A float trait."""
847
844
848 evaluate = float
849 default_value = 0.0
845 default_value = 0.0
850 info_text = 'a float'
846 info_text = 'a float'
851
847
@@ -869,7 +865,6 b' class CFloat(Float):'
869 class Complex(TraitType):
865 class Complex(TraitType):
870 """A trait for complex numbers."""
866 """A trait for complex numbers."""
871
867
872 evaluate = complex
873 default_value = 0.0 + 0.0j
868 default_value = 0.0 + 0.0j
874 info_text = 'a complex number'
869 info_text = 'a complex number'
875
870
@@ -894,7 +889,6 b' class CComplex(Complex):'
894 class Str(TraitType):
889 class Str(TraitType):
895 """A trait for strings."""
890 """A trait for strings."""
896
891
897 evaluate = lambda x: x
898 default_value = ''
892 default_value = ''
899 info_text = 'a string'
893 info_text = 'a string'
900
894
@@ -920,7 +914,6 b' class CStr(Str):'
920 class Unicode(TraitType):
914 class Unicode(TraitType):
921 """A trait for unicode strings."""
915 """A trait for unicode strings."""
922
916
923 evaluate = unicode
924 default_value = u''
917 default_value = u''
925 info_text = 'a unicode string'
918 info_text = 'a unicode string'
926
919
@@ -944,7 +937,7 b' class CUnicode(Unicode):'
944
937
945 class Bool(TraitType):
938 class Bool(TraitType):
946 """A boolean (True, False) trait."""
939 """A boolean (True, False) trait."""
947 evaluate = bool
940
948 default_value = False
941 default_value = False
949 info_text = 'a boolean'
942 info_text = 'a boolean'
950
943
@@ -1023,3 +1016,23 b' class List(Instance):'
1023
1016
1024 super(List,self).__init__(klass=list, args=args,
1017 super(List,self).__init__(klass=list, args=args,
1025 allow_none=allow_none, **metadata)
1018 allow_none=allow_none, **metadata)
1019
1020
1021 class TCPAddress(TraitType):
1022 """A trait for an (ip, port) tuple.
1023
1024 This allows for both IPv4 IP addresses as well as hostnames.
1025 """
1026
1027 default_value = ('127.0.0.1', 0)
1028 info_text = 'an (ip, port) tuple'
1029
1030 def validate(self, obj, value):
1031 if isinstance(value, tuple):
1032 if len(value) == 2:
1033 if isinstance(value[0], basestring) and isinstance(value[1], int):
1034 port = value[1]
1035 if port >= 0 and port <= 65535:
1036 return value
1037 self.error(obj, value)
1038
@@ -1,4 +1,4 b''
1 """Classes to manage the interaction with a running kernel.
1 """Base classes to manage the interaction with a running kernel.
2
2
3 Todo
3 Todo
4 ====
4 ====
@@ -29,7 +29,7 b' from zmq import POLLIN, POLLOUT, POLLERR'
29 from zmq.eventloop import ioloop
29 from zmq.eventloop import ioloop
30
30
31 # Local imports.
31 # Local imports.
32 from IPython.utils.traitlets import HasTraits, Any, Instance, Type
32 from IPython.utils.traitlets import HasTraits, Any, Instance, Type, TCPAddress
33 from kernel import launch_kernel
33 from kernel import launch_kernel
34 from session import Session
34 from session import Session
35
35
@@ -61,9 +61,9 b' class ZmqSocketChannel(Thread):'
61
61
62 Parameters
62 Parameters
63 ----------
63 ----------
64 context : zmq.Context
64 context : :class:`zmq.Context`
65 The ZMQ context to use.
65 The ZMQ context to use.
66 session : session.Session
66 session : :class:`session.Session`
67 The session to use.
67 The session to use.
68 address : tuple
68 address : tuple
69 Standard (ip, port) tuple that the kernel is listening on.
69 Standard (ip, port) tuple that the kernel is listening on.
@@ -289,6 +289,10 b' class SubSocketChannel(ZmqSocketChannel):'
289 def flush(self, timeout=1.0):
289 def flush(self, timeout=1.0):
290 """Immediately processes all pending messages on the SUB channel.
290 """Immediately processes all pending messages on the SUB channel.
291
291
292 Callers should use this method to ensure that :method:`call_handlers`
293 has been called for all messages that have been received on the
294 0MQ SUB socket of this channel.
295
292 This method is thread safe.
296 This method is thread safe.
293
297
294 Parameters
298 Parameters
@@ -324,7 +328,7 b' class SubSocketChannel(ZmqSocketChannel):'
324 msg = self.socket.recv_json(zmq.NOBLOCK)
328 msg = self.socket.recv_json(zmq.NOBLOCK)
325 except zmq.ZMQError:
329 except zmq.ZMQError:
326 # Check the errno?
330 # Check the errno?
327 # Will this tigger POLLERR?
331 # Will this trigger POLLERR?
328 break
332 break
329 else:
333 else:
330 self.call_handlers(msg)
334 self.call_handlers(msg)
@@ -435,9 +439,9 b' class KernelManager(HasTraits):'
435 rep_channel_class = Type(RepSocketChannel)
439 rep_channel_class = Type(RepSocketChannel)
436
440
437 # Protected traits.
441 # Protected traits.
438 _xreq_address = Any
442 _xreq_address = TCPAddress
439 _sub_address = Any
443 _sub_address = TCPAddress
440 _rep_address = Any
444 _rep_address = TCPAddress
441 _xreq_channel = Any
445 _xreq_channel = Any
442 _sub_channel = Any
446 _sub_channel = Any
443 _rep_channel = Any
447 _rep_channel = Any
@@ -585,4 +589,3 b' class KernelManager(HasTraits):'
585 def rep_address(self):
589 def rep_address(self):
586 return self._rep_address
590 return self._rep_address
587
591
588
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now