##// END OF EJS Templates
remove uneccesary Config objects from flags.
remove uneccesary Config objects from flags.

File last commit:

r3988:5f4abd15
r3994:d5516357
Show More
factory.py
95 lines | 3.7 KiB | text/x-python | PythonLexer
MinRK
Refactor newparallel to use Config system...
r3604 """Base config factories."""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2009 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import logging
MinRK
resort imports in a cleaner order
r3631 import os
MinRK
Refactor newparallel to use Config system...
r3604
from zmq.eventloop.ioloop import IOLoop
from IPython.config.configurable import Configurable
MinRK
cleanup parallel traits...
r3988 from IPython.utils.traitlets import Int, Instance, Unicode
MinRK
Refactor newparallel to use Config system...
r3604
MinRK
move IPython.zmq.parallel to IPython.parallel
r3666 import IPython.parallel.streamsession as ss
MinRK
organize IPython.parallel into subpackages
r3673 from IPython.parallel.util import select_random_ports
MinRK
Refactor newparallel to use Config system...
r3604
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
MinRK
rework logging connections
r3610 class LoggingFactory(Configurable):
"""A most basic class, that has a `log` (type:`Logger`) attribute, set via a `logname` Trait."""
log = Instance('logging.Logger', ('ZMQ', logging.WARN))
MinRK
cleanup parallel traits...
r3988 logname = Unicode('ZMQ')
MinRK
rework logging connections
r3610 def _logname_changed(self, name, old, new):
self.log = logging.getLogger(new)
MinRK
Refactor newparallel to use Config system...
r3604
MinRK
rework logging connections
r3610 class SessionFactory(LoggingFactory):
MinRK
move IPython.zmq.parallel to IPython.parallel
r3666 """The Base factory from which every factory in IPython.parallel inherits"""
MinRK
Refactor newparallel to use Config system...
r3604
# not configurable:
context = Instance('zmq.Context', (), {})
MinRK
move IPython.zmq.parallel to IPython.parallel
r3666 session = Instance('IPython.parallel.streamsession.StreamSession')
MinRK
rework logging connections
r3610 loop = Instance('zmq.eventloop.ioloop.IOLoop', allow_none=False)
MinRK
Refactor newparallel to use Config system...
r3604 def _loop_default(self):
return IOLoop.instance()
MinRK
rework logging connections
r3610
MinRK
Refactor newparallel to use Config system...
r3604 def __init__(self, **kwargs):
super(SessionFactory, self).__init__(**kwargs)
# construct the session
MinRK
all ipcluster scripts in some degree of working order with new config
r3985 self.session = ss.StreamSession(**kwargs)
MinRK
Refactor newparallel to use Config system...
r3604
class RegistrationFactory(SessionFactory):
"""The Base Configurable for objects that involve registration."""
MinRK
cleanup parallel traits...
r3988 url = Unicode('', config=True,
MinRK
all ipcluster scripts in some degree of working order with new config
r3985 help="""The 0MQ url used for registration. This sets transport, ip, and port
in one variable. For example: url='tcp://127.0.0.1:12345' or
url='epgm://*:90210'""") # url takes precedence over ip,regport,transport
MinRK
cleanup parallel traits...
r3988 transport = Unicode('tcp', config=True,
MinRK
all ipcluster scripts in some degree of working order with new config
r3985 help="""The 0MQ transport for communications. This will likely be
the default of 'tcp', but other values include 'ipc', 'epgm', 'inproc'.""")
MinRK
cleanup parallel traits...
r3988 ip = Unicode('127.0.0.1', config=True,
MinRK
all ipcluster scripts in some degree of working order with new config
r3985 help="""The IP address for registration. This is generally either
'127.0.0.1' for loopback only or '*' for all interfaces.
[default: '127.0.0.1']""")
regport = Int(config=True,
help="""The port on which the Hub listens for registration.""")
MinRK
Refactor newparallel to use Config system...
r3604 def _regport_default(self):
MinRK
persist connection data to disk as json
r3614 return select_random_ports(1)[0]
MinRK
Refactor newparallel to use Config system...
r3604
def __init__(self, **kwargs):
super(RegistrationFactory, self).__init__(**kwargs)
self._propagate_url()
self._rebuild_url()
self.on_trait_change(self._propagate_url, 'url')
self.on_trait_change(self._rebuild_url, 'ip')
self.on_trait_change(self._rebuild_url, 'transport')
self.on_trait_change(self._rebuild_url, 'regport')
def _rebuild_url(self):
self.url = "%s://%s:%i"%(self.transport, self.ip, self.regport)
def _propagate_url(self):
"""Ensure self.url contains full transport://interface:port"""
if self.url:
iface = self.url.split('://',1)
if len(iface) == 2:
self.transport,iface = iface
iface = iface.split(':')
self.ip = iface[0]
if iface[1]:
self.regport = int(iface[1])