##// END OF EJS Templates
Revert "use testpath.tempdir for utils.tempdir"
Revert "use testpath.tempdir for utils.tempdir"

File last commit:

r20860:c3b763db
r21102:3abb325f
Show More
factory.py
73 lines | 2.8 KiB | text/x-python | PythonLexer
MinRK
update recently changed modules with Authors in docstring
r4018 """Base config factories.
Authors:
* Min RK
"""
MinRK
Refactor newparallel to use Config system...
r3604
#-----------------------------------------------------------------------------
MinRK
reorganize Factory classes to follow relocation of Session object
r4007 # Copyright (C) 2010-2011 The IPython Development Team
MinRK
Refactor newparallel to use Config system...
r3604 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
MinRK
avoid executing code in utils.localinterfaces at import time...
r12591 from IPython.utils.localinterfaces import localhost
Spencer Nelson
Remove unused imports
r16525 from IPython.utils.traitlets import Integer, Unicode
MinRK
Refactor newparallel to use Config system...
r3604
Min RK
s/IPython.parallel/ipython_parallel/
r20860 from ipython_parallel.util import select_random_ports
Spencer Nelson
Remove unused imports
r16525 from IPython.kernel.zmq.session import SessionFactory
MinRK
Refactor newparallel to use Config system...
r3604
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
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
MinRK
avoid executing code in utils.localinterfaces at import time...
r12591 in one variable. For example: url='tcp://127.0.0.1:12345' or
W. Trevor King
parallel: Use utils.localinterfaces.LOCALHOST
r9254 url='epgm://*:90210'"""
MinRK
avoid executing code in utils.localinterfaces at import time...
r12591 ) # 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
avoid executing code in utils.localinterfaces at import time...
r12591 ip = Unicode(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.
MinRK
avoid executing code in utils.localinterfaces at import time...
r12591 """)
def _ip_default(self):
return localhost()
MinRK
add Integer traitlet...
r5344 regport = Integer(config=True,
MinRK
all ipcluster scripts in some degree of working order with new config
r3985 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])