Esempio n. 1
0
    def resolve_file_path(self, filename, ipythondir=None):
        """Resolve filenames into absolute paths.

        This function looks in the following directories in order:

        1.  In the current working directory or by absolute path with ~ expanded
        2.  In ipythondir if that is set
        3.  In the IPYTHONDIR environment variable if it exists
        4.  In the ~/.ipython directory

        Note: The IPYTHONDIR is also used by the trunk version of IPython so
               changing it will also affect it was well.
        """

        # In cwd or by absolute path with ~ expanded
        trythis = os.path.expanduser(filename)
        if os.path.isfile(trythis):
            return trythis

        # In ipythondir if it is set
        if ipythondir is not None:
            trythis = ipythondir + '/' + filename
            if os.path.isfile(trythis):
                return trythis

        trythis = get_ipython_dir() + '/' + filename
        if os.path.isfile(trythis):
            return trythis

        return None
 def _getEngineInfoLogFile(self):
     # Store all logs inside the ipython directory
     ipdir = cutils.get_ipython_dir()
     pjoin = os.path.join
     logdir_base = pjoin(ipdir,'log')
     if not os.path.isdir(logdir_base):
         os.makedirs(logdir_base)
     logfile = os.path.join(logdir_base,'ipcontroller-%s-engine-info.log' % os.getpid())
     return logfile
Esempio n. 3
0
def clusterRemote(opt, arg):
    """Start a remote cluster over SSH"""

    # Load the remote cluster configuration
    clConfig = {}
    execfile(opt.clusterfile, clConfig)
    contConfig = clConfig['controller']
    engConfig = clConfig['engines']
    # Determine where to find sshx:
    sshx = clConfig.get('sshx', os.environ.get('IPYTHON_SSHX', 'sshx'))

    # Store all logs inside the ipython directory
    ipdir = cutils.get_ipython_dir()
    pjoin = os.path.join

    logfile = opt.logfile
    if logfile is None:
        logdir_base = pjoin(ipdir, 'log')
        ensureDir(logdir_base)
        logfile = pjoin(logdir_base, 'ipcluster')

    # Append this script's PID to the logfile name always
    logfile = '%s-%s' % (logfile, os.getpid())

    print 'Starting controller:'
    # Controller data:
    xsys = os.system

    contHost = contConfig['host']
    contLog = '%s-con-%s-' % (logfile, contHost)
    cmd = "ssh %s '%s' 'ipcontroller --logfile %s' &" % \
          (contHost,sshx,contLog)
    #print 'cmd:<%s>' % cmd  # dbg
    xsys(cmd)
    time.sleep(2)

    print 'Starting engines:   '
    for engineHost, engineData in engConfig.iteritems():
        if isinstance(engineData, int):
            numEngines = engineData
        else:
            raise NotImplementedError(
                'port configuration not finished for engines')

        print 'Sarting %d engines on %s' % (numEngines, engineHost)
        engLog = '%s-eng-%s-' % (logfile, engineHost)
        for i in range(numEngines):
            cmd = "ssh %s '%s' 'ipengine --controller-ip %s --logfile %s' &" % \
                      (engineHost,sshx,contHost,engLog)
            #print 'cmd:<%s>' % cmd  # dbg
            xsys(cmd)
        # Wait after each host a little bit
        time.sleep(1)

    startMsg(contConfig['host'])
Esempio n. 4
0
 def write_default_config_file(self):
     ipdir = get_ipython_dir()
     fname = ipdir + '/' + self.filename
     if not os.path.isfile(fname):
         print "Writing the configuration file to: " + fname
         self.write_config_obj_to_file(fname)
Esempio n. 5
0
def clusterLocal(opt, arg):
    """Start a cluster on the local machine."""

    # Store all logs inside the ipython directory
    ipdir = cutils.get_ipython_dir()
    pjoin = os.path.join

    logfile = opt.logfile
    if logfile is None:
        logdir_base = pjoin(ipdir, 'log')
        ensureDir(logdir_base)
        logfile = pjoin(logdir_base, 'ipcluster-')

    print 'Starting controller:',
    controller = Popen(['ipcontroller', '--logfile', logfile])
    print 'Controller PID:', controller.pid

    print 'Starting engines:   ',
    time.sleep(3)

    englogfile = '%s%s-' % (logfile, controller.pid)
    engines = [
        Popen(['ipengine', '--logfile', englogfile]) for i in range(opt.n)
    ]
    eids = [e.pid for e in engines]
    print 'Engines PIDs:  ', eids
    print 'Log files: %s*' % englogfile

    proc_ids = eids + [controller.pid]
    procs = engines + [controller]

    grpid = os.getpgrp()
    try:
        startMsg('127.0.0.1')
        print 'You can also hit Ctrl-C to stop it, or use from the cmd line:'
        print
        print 'kill -INT', grpid
        print
        try:
            while True:
                time.sleep(5)
        except:
            pass
    finally:
        print 'Stopping cluster.  Cleaning up...'
        cleanup(stop, controller, engines)
        for i in range(4):
            time.sleep(i + 2)
            nZombies = numAlive(controller, engines)
            if nZombies == 0:
                print 'OK: All processes cleaned up.'
                break
            print 'Trying again, %d processes did not stop...' % nZombies
            cleanup(kill, controller, engines)
            if numAlive(controller, engines) == 0:
                print 'OK: All processes cleaned up.'
                break
        else:
            print '*' * 75
            print 'ERROR: could not kill some processes, try to do it',
            print 'manually.'
            zombies = []
            if controller.returncode is None:
                print 'Controller is alive: pid =', controller.pid
                zombies.append(controller.pid)
            liveEngines = [e for e in engines if e.returncode is None]
            for e in liveEngines:
                print 'Engine is alive:     pid =', e.pid
                zombies.append(e.pid)
            print
            print 'Zombie summary:', ' '.join(map(str, zombies))
Esempio n. 6
0
#-------------------------------------------------------------------------------

from ipython1.external.configobj import ConfigObj
from ipython1.config.cutils import get_ipython_dir
from ipython1.config.api import ConfigObjManager

defaultNotebookConfig = ConfigObj()

#-------------------------------------------------------------------------------
# Notebook Configuration
#-------------------------------------------------------------------------------

notebookConfig = {
    'engineInterface': 'ipython1.kernel.engineservice.IEngineQueued',
    'networkInterfaces': {
        'http': {
            'interface':
            'ipython1.notebook.notebookhttp.IHTTPNotebookServerFactory',
            'ip': '',
            'port': 8008
        }
    },
    'defaultDBMode': "sqlite///",
    'activeDB': "sqlite:///%s/ipnotebooks.db" % (get_ipython_dir()),
    'externalDBs': []
}

defaultNotebookConfig['notebook'] = notebookConfig

configManager = ConfigObjManager(defaultNotebookConfig,
                                 'ipython1.notebook.ini')