Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removing old IPython.kernel Twisted based code.

  • Loading branch information...
commit b837f1075973d4e8938317e80d9b9b24961c56c4 1 parent 6301a14
@ellisonbg authored
Showing with 0 additions and 17,235 deletions.
  1. +0 −25 IPython/kernel/__init__.py
  2. +0 −42 IPython/kernel/asyncclient.py
  3. +0 −110 IPython/kernel/client.py
  4. +0 −788 IPython/kernel/clientconnector.py
  5. +0 −32 IPython/kernel/clientinterfaces.py
  6. +0 −538 IPython/kernel/clusterdir.py
  7. +0 −39 IPython/kernel/codeutil.py
  8. +0 −79 IPython/kernel/configobjfactory.py
  9. +0 −374 IPython/kernel/controllerservice.py
  10. +0 −16 IPython/kernel/core/__init__.py
  11. +0 −70 IPython/kernel/core/display_formatter.py
  12. +0 −100 IPython/kernel/core/display_trap.py
  13. +0 −41 IPython/kernel/core/error.py
  14. +0 −81 IPython/kernel/core/fd_redirector.py
  15. +0 −66 IPython/kernel/core/file_like.py
  16. +0 −137 IPython/kernel/core/history.py
  17. +0 −760 IPython/kernel/core/interpreter.py
  18. +0 −34 IPython/kernel/core/macro.py
  19. +0 −147 IPython/kernel/core/magic.py
  20. +0 −98 IPython/kernel/core/message_cache.py
  21. +0 −107 IPython/kernel/core/output_trap.py
  22. +0 −588 IPython/kernel/core/prompts.py
  23. +0 −97 IPython/kernel/core/redirector_output_trap.py
  24. +0 −53 IPython/kernel/core/sync_traceback_trap.py
  25. +0 −10 IPython/kernel/core/tests/__init__.py
  26. +0 −62 IPython/kernel/core/tests/test_interpreter.py
  27. +0 −79 IPython/kernel/core/tests/test_redirectors.py
  28. +0 −62 IPython/kernel/core/traceback_formatter.py
  29. +0 −85 IPython/kernel/core/traceback_trap.py
  30. +0 −195 IPython/kernel/core/util.py
  31. +0 −138 IPython/kernel/engineconnector.py
  32. +0 −544 IPython/kernel/enginefc.py
  33. +0 −903 IPython/kernel/engineservice.py
  34. +0 −234 IPython/kernel/error.py
  35. +0 −296 IPython/kernel/fcutil.py
  36. +0 −499 IPython/kernel/ipclusterapp.py
  37. +0 −271 IPython/kernel/ipcontrollerapp.py
  38. +0 −242 IPython/kernel/ipengineapp.py
  39. +0 −834 IPython/kernel/launcher.py
  40. +0 −121 IPython/kernel/map.py
  41. +0 −232 IPython/kernel/mapper.py
  42. +0 −745 IPython/kernel/multiengine.py
  43. +0 −905 IPython/kernel/multiengineclient.py
  44. +0 −760 IPython/kernel/multienginefc.py
  45. +0 −170 IPython/kernel/newserialized.py
  46. +0 −107 IPython/kernel/parallelfunction.py
  47. +0 −34 IPython/kernel/pbconfig.py
  48. +0 −92 IPython/kernel/pbutil.py
  49. +0 −174 IPython/kernel/pendingdeferred.py
  50. +0 −82 IPython/kernel/pickleutil.py
  51. +0 −16 IPython/kernel/scripts/__init__.py
  52. +0 −18 IPython/kernel/scripts/ipcluster
  53. +0 −18 IPython/kernel/scripts/ipcontroller
  54. +0 −20 IPython/kernel/scripts/ipengine
  55. +0 −1,115 IPython/kernel/task.py
  56. +0 −198 IPython/kernel/taskclient.py
  57. +0 −329 IPython/kernel/taskfc.py
  58. +0 −10 IPython/kernel/tests/__init__.py
  59. +0 −102 IPython/kernel/tests/controllertest.py
  60. +0 −377 IPython/kernel/tests/engineservicetest.py
  61. +0 −827 IPython/kernel/tests/multienginetest.py
  62. +0 −247 IPython/kernel/tests/tasktest.py
  63. +0 −44 IPython/kernel/tests/test_controllerservice.py
  64. +0 −92 IPython/kernel/tests/test_enginefc.py
  65. +0 −79 IPython/kernel/tests/test_engineservice.py
  66. +0 −55 IPython/kernel/tests/test_multiengine.py
  67. +0 −146 IPython/kernel/tests/test_multienginefc.py
  68. +0 −102 IPython/kernel/tests/test_newserialized.py
  69. +0 −186 IPython/kernel/tests/test_pendingdeferred.py
  70. +0 −51 IPython/kernel/tests/test_task.py
  71. +0 −162 IPython/kernel/tests/test_taskfc.py
  72. +0 −51 IPython/kernel/tests/test_twistedutil.py
  73. +0 −274 IPython/kernel/twistedutil.py
  74. +0 −102 IPython/kernel/util.py
  75. +0 −316 IPython/kernel/winhpcjob.py
View
25 IPython/kernel/__init__.py
@@ -1,25 +0,0 @@
-# encoding: utf-8
-"""The IPython1 kernel.
-
-The IPython kernel actually refers to three things:
-
- * The IPython Engine
- * The IPython Controller
- * Clients to the IPython Controller
-
-The kernel module implements the engine, controller and client and all the
-network protocols needed for the various entities to talk to each other.
-
-An end user should probably begin by looking at the `client.py` module
-if they need blocking clients or in `asyncclient.py` if they want asynchronous,
-deferred/Twisted using clients.
-"""
-__docformat__ = "restructuredtext en"
-#-----------------------------------------------------------------------------
-# Copyright (C) 2008 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.
-#-----------------------------------------------------------------------------
-
-from IPython.kernel.error import TaskRejectError
View
42 IPython/kernel/asyncclient.py
@@ -1,42 +0,0 @@
-#!/usr/bin/env python
-# encoding: utf-8
-
-"""Asynchronous clients for the IPython controller.
-
-This module has clients for using the various interfaces of the controller
-in a fully asynchronous manner. This means that you will need to run the
-Twisted reactor yourself and that all methods of the client classes return
-deferreds to the result.
-
-The main methods are are `get_*_client` and `get_client`.
-"""
-#-----------------------------------------------------------------------------
-# 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
-#-----------------------------------------------------------------------------
-
-from IPython.kernel import codeutil
-from IPython.kernel.clientconnector import (
- AsyncClientConnector,
- AsyncCluster
-)
-
-# Other things that the user will need
-from IPython.kernel.task import MapTask, StringTask
-from IPython.kernel.error import CompositeError
-
-#-----------------------------------------------------------------------------
-# Code
-#-----------------------------------------------------------------------------
-
-_client_tub = AsyncClientConnector()
-get_multiengine_client = _client_tub.get_multiengine_client
-get_task_client = _client_tub.get_task_client
-get_client = _client_tub.get_client
-
View
110 IPython/kernel/client.py
@@ -1,110 +0,0 @@
-#!/usr/bin/env python
-# encoding: utf-8
-
-"""This module contains blocking clients for the controller interfaces.
-
-Unlike the clients in `asyncclient.py`, the clients in this module are fully
-blocking. This means that methods on the clients return the actual results
-rather than a deferred to the result. Also, we manage the Twisted reactor
-for you. This is done by running the reactor in a thread.
-
-The main classes in this module are:
-
- * MultiEngineClient
- * TaskClient
- * Task
- * CompositeError
-"""
-
-#-----------------------------------------------------------------------------
-# 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.
-#-----------------------------------------------------------------------------
-
-#-----------------------------------------------------------------------------
-# Warnings control
-#-----------------------------------------------------------------------------
-
-import warnings
-
-# Twisted generates annoying warnings with Python 2.6, as will do other code
-# that imports 'sets' as of today
-warnings.filterwarnings('ignore', 'the sets module is deprecated',
- DeprecationWarning )
-
-# This one also comes from Twisted
-warnings.filterwarnings('ignore', 'the sha module is deprecated',
- DeprecationWarning)
-
-#-----------------------------------------------------------------------------
-# Imports
-#-----------------------------------------------------------------------------
-
-import sys
-
-import twisted
-from twisted.internet import reactor
-from twisted.python import log
-
-from IPython.kernel.clientconnector import ClientConnector, Cluster
-from IPython.kernel.twistedutil import ReactorInThread
-from IPython.kernel.twistedutil import blockingCallFromThread
-
-# These enable various things
-from IPython.kernel import codeutil
-
-# Other things that the user will need
-from IPython.kernel.task import MapTask, StringTask
-from IPython.kernel.error import CompositeError
-
-#-------------------------------------------------------------------------------
-# Code
-#-------------------------------------------------------------------------------
-
-# PotentialZombieWarning is deprecated from Twisted 10.0.0 and above and
-# using the filter on > 10.0.0 creates a warning itself.
-if twisted.version.major < 10:
- from twisted.internet.error import PotentialZombieWarning
- warnings.simplefilter('ignore', PotentialZombieWarning)
-
-_client_tub = ClientConnector()
-
-get_multiengine_client = _client_tub.get_multiengine_client
-get_task_client = _client_tub.get_task_client
-MultiEngineClient = get_multiengine_client
-TaskClient = get_task_client
-
-# This isn't great. I should probably set this up in the ReactorInThread
-# class below. But, it does work for now.
-log.startLogging(sys.stdout, setStdout=0)
-
-def _result_list_printer(obj, p, cycle):
- if cycle:
- return p.text('ResultList(...)')
- return p.text(repr(obj))
-
-# ResultList is a list subclass and will use the default pretty printer.
-# This overrides that to use the __repr__ of ResultList.
-ip = get_ipython()
-ip.display_formatter.formatters['text/plain'].for_type_by_name(
- 'IPython.kernel.multiengineclient', 'ResultList', _result_list_printer
-)
-
-# Now we start the reactor in a thread
-rit = ReactorInThread()
-rit.setDaemon(True)
-rit.start()
-
-
-__all__ = [
- 'MapTask',
- 'StringTask',
- 'MultiEngineClient',
- 'TaskClient',
- 'CompositeError',
- 'get_task_client',
- 'get_multiengine_client',
- 'Cluster'
-]
View
788 IPython/kernel/clientconnector.py
@@ -1,788 +0,0 @@
-# encoding: utf-8
-"""Facilities for handling client connections to the controller."""
-
-#-----------------------------------------------------------------------------
-# 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
-#-----------------------------------------------------------------------------
-
-from __future__ import with_statement
-import os
-
-from IPython.kernel.fcutil import (
- Tub,
- find_furl,
- is_valid_furl,
- is_valid_furl_file,
- is_valid_furl_or_file,
- validate_furl_or_file,
- FURLError
-)
-from IPython.kernel.clusterdir import ClusterDir, ClusterDirError
-from IPython.kernel.launcher import IPClusterLauncher
-from IPython.kernel.twistedutil import (
- gatherBoth,
- make_deferred,
- blockingCallFromThread,
- sleep_deferred
-)
-from IPython.utils.importstring import import_item
-from IPython.utils.path import get_ipython_dir
-
-from twisted.internet import defer
-from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.python import failure, log
-
-#-----------------------------------------------------------------------------
-# The ClientConnector class
-#-----------------------------------------------------------------------------
-
-DELAY = 0.2
-MAX_TRIES = 9
-
-
-class ClientConnectorError(Exception):
- pass
-
-
-class AsyncClientConnector(object):
- """A class for getting remote references and clients from furls.
-
- This start a single :class:`Tub` for all remote reference and caches
- references.
- """
-
- def __init__(self):
- self._remote_refs = {}
- self.tub = Tub()
- self.tub.startService()
-
- def _find_furl(self, profile='default', cluster_dir=None,
- furl_or_file=None, furl_file_name=None,
- ipython_dir=None):
- """Find a FURL file.
-
- If successful, this returns a FURL file that exists on the file
- system. The contents of the file have not been checked though. This
- is because we often have to deal with FURL file whose buffers have
- not been flushed.
-
- This raises an :exc:`~IPython.kernel.fcutil.FURLError` exception
- if a FURL file can't be found.
-
- This tries the following:
-
- 1. By the name ``furl_or_file``.
- 2. By ``cluster_dir`` and ``furl_file_name``.
- 3. By cluster profile with a default of ``default``. This uses
- ``ipython_dir``.
- """
- # Try by furl_or_file
- if furl_or_file is not None:
- if is_valid_furl_or_file(furl_or_file):
- return furl_or_file
-
- if furl_file_name is None:
- raise FURLError('A furl_file_name must be provided if furl_or_file is not')
-
- # Try by cluster_dir
- if cluster_dir is not None:
- cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir)
- sdir = cluster_dir_obj.security_dir
- furl_file = os.path.join(sdir, furl_file_name)
- validate_furl_or_file(furl_file)
- return furl_file
-
- # Try by profile
- if ipython_dir is None:
- ipython_dir = get_ipython_dir()
- if profile is not None:
- cluster_dir_obj = ClusterDir.find_cluster_dir_by_profile(
- ipython_dir, profile)
- sdir = cluster_dir_obj.security_dir
- furl_file = os.path.join(sdir, furl_file_name)
- validate_furl_or_file(furl_file)
- return furl_file
-
- raise FURLError('Could not find a valid FURL file.')
-
- def get_reference(self, furl_or_file):
- """Get a remote reference using a furl or a file containing a furl.
-
- Remote references are cached locally so once a remote reference
- has been retrieved for a given furl, the cached version is
- returned.
-
- Parameters
- ----------
- furl_or_file : str
- A furl or a filename containing a furl. This should already be
- validated, but might not yet exist.
-
- Returns
- -------
- A deferred to a remote reference
- """
- furl = furl_or_file
- if furl in self._remote_refs:
- d = defer.succeed(self._remote_refs[furl])
- else:
- d = self.tub.getReference(furl)
- d.addCallback(self._save_ref, furl)
- return d
-
- def _save_ref(self, ref, furl):
- """Cache a remote reference by its furl."""
- self._remote_refs[furl] = ref
- return ref
-
- def get_task_client(self, profile='default', cluster_dir=None,
- furl_or_file=None, ipython_dir=None,
- delay=DELAY, max_tries=MAX_TRIES):
- """Get the task controller client.
-
- This method is a simple wrapper around `get_client` that passes in
- the default name of the task client FURL file. Usually only
- the ``profile`` option will be needed. If a FURL file can't be
- found by its profile, use ``cluster_dir`` or ``furl_or_file``.
-
- Parameters
- ----------
- profile : str
- The name of a cluster directory profile (default="default"). The
- cluster directory "cluster_<profile>" will be searched for
- in ``os.getcwd()``, the ipython_dir and then in the directories
- listed in the :env:`IPCLUSTER_DIR_PATH` environment variable.
- cluster_dir : str
- The full path to a cluster directory. This is useful if profiles
- are not being used.
- furl_or_file : str
- A furl or a filename containing a FURL. This is useful if you
- simply know the location of the FURL file.
- ipython_dir : str
- The location of the ipython_dir if different from the default.
- This is used if the cluster directory is being found by profile.
- delay : float
- The initial delay between re-connection attempts. Susequent delays
- get longer according to ``delay[i] = 1.5*delay[i-1]``.
- max_tries : int
- The max number of re-connection attempts.
-
- Returns
- -------
- A deferred to the actual client class.
- """
- return self.get_client(
- profile, cluster_dir, furl_or_file,
- 'ipcontroller-tc.furl', ipython_dir,
- delay, max_tries
- )
-
- def get_multiengine_client(self, profile='default', cluster_dir=None,
- furl_or_file=None, ipython_dir=None,
- delay=DELAY, max_tries=MAX_TRIES):
- """Get the multiengine controller client.
-
- This method is a simple wrapper around `get_client` that passes in
- the default name of the task client FURL file. Usually only
- the ``profile`` option will be needed. If a FURL file can't be
- found by its profile, use ``cluster_dir`` or ``furl_or_file``.
-
- Parameters
- ----------
- profile : str
- The name of a cluster directory profile (default="default"). The
- cluster directory "cluster_<profile>" will be searched for
- in ``os.getcwd()``, the ipython_dir and then in the directories
- listed in the :env:`IPCLUSTER_DIR_PATH` environment variable.
- cluster_dir : str
- The full path to a cluster directory. This is useful if profiles
- are not being used.
- furl_or_file : str
- A furl or a filename containing a FURL. This is useful if you
- simply know the location of the FURL file.
- ipython_dir : str
- The location of the ipython_dir if different from the default.
- This is used if the cluster directory is being found by profile.
- delay : float
- The initial delay between re-connection attempts. Susequent delays
- get longer according to ``delay[i] = 1.5*delay[i-1]``.
- max_tries : int
- The max number of re-connection attempts.
-
- Returns
- -------
- A deferred to the actual client class.
- """
- return self.get_client(
- profile, cluster_dir, furl_or_file,
- 'ipcontroller-mec.furl', ipython_dir,
- delay, max_tries
- )
-
- def get_client(self, profile='default', cluster_dir=None,
- furl_or_file=None, furl_file_name=None, ipython_dir=None,
- delay=DELAY, max_tries=MAX_TRIES):
- """Get a remote reference and wrap it in a client by furl.
-
- This method is a simple wrapper around `get_client` that passes in
- the default name of the task client FURL file. Usually only
- the ``profile`` option will be needed. If a FURL file can't be
- found by its profile, use ``cluster_dir`` or ``furl_or_file``.
-
- Parameters
- ----------
- profile : str
- The name of a cluster directory profile (default="default"). The
- cluster directory "cluster_<profile>" will be searched for
- in ``os.getcwd()``, the ipython_dir and then in the directories
- listed in the :env:`IPCLUSTER_DIR_PATH` environment variable.
- cluster_dir : str
- The full path to a cluster directory. This is useful if profiles
- are not being used.
- furl_or_file : str
- A furl or a filename containing a FURL. This is useful if you
- simply know the location of the FURL file.
- furl_file_name : str
- The filename (not the full path) of the FURL. This must be
- provided if ``furl_or_file`` is not.
- ipython_dir : str
- The location of the ipython_dir if different from the default.
- This is used if the cluster directory is being found by profile.
- delay : float
- The initial delay between re-connection attempts. Susequent delays
- get longer according to ``delay[i] = 1.5*delay[i-1]``.
- max_tries : int
- The max number of re-connection attempts.
-
- Returns
- -------
- A deferred to the actual client class. Or a failure to a
- :exc:`FURLError`.
- """
- try:
- furl_file = self._find_furl(
- profile, cluster_dir, furl_or_file,
- furl_file_name, ipython_dir
- )
- # If this succeeds, we know the furl file exists and has a .furl
- # extension, but it could still be empty. That is checked each
- # connection attempt.
- except FURLError:
- return defer.fail(failure.Failure())
-
- def _wrap_remote_reference(rr):
- d = rr.callRemote('get_client_name')
- d.addCallback(lambda name: import_item(name))
- def adapt(client_interface):
- client = client_interface(rr)
- client.tub = self.tub
- return client
- d.addCallback(adapt)
-
- return d
-
- d = self._try_to_connect(furl_file, delay, max_tries, attempt=0)
- d.addCallback(_wrap_remote_reference)
- d.addErrback(self._handle_error, furl_file)
- return d
-
- def _handle_error(self, f, furl_file):
- raise ClientConnectorError('Could not connect to the controller '
- 'using the FURL file. This usually means that i) the controller '
- 'was not started or ii) a firewall was blocking the client from '
- 'connecting to the controller: %s' % furl_file)
-
- @inlineCallbacks
- def _try_to_connect(self, furl_or_file, delay, max_tries, attempt):
- """Try to connect to the controller with retry logic."""
- if attempt < max_tries:
- log.msg("Connecting [%r]" % attempt)
- try:
- self.furl = find_furl(furl_or_file)
- # Uncomment this to see the FURL being tried.
- # log.msg("FURL: %s" % self.furl)
- rr = yield self.get_reference(self.furl)
- log.msg("Connected: %s" % furl_or_file)
- except:
- if attempt==max_tries-1:
- # This will propagate the exception all the way to the top
- # where it can be handled.
- raise
- else:
- yield sleep_deferred(delay)
- rr = yield self._try_to_connect(
- furl_or_file, 1.5*delay, max_tries, attempt+1
- )
- returnValue(rr)
- else:
- returnValue(rr)
- else:
- raise ClientConnectorError(
- 'Could not connect to controller, max_tries (%r) exceeded. '
- 'This usually means that i) the controller was not started, '
- 'or ii) a firewall was blocking the client from connecting '
- 'to the controller.' % max_tries
- )
-
-
-class ClientConnector(object):
- """A blocking version of a client connector.
-
- This class creates a single :class:`Tub` instance and allows remote
- references and client to be retrieved by their FURLs. Remote references
- are cached locally and FURL files can be found using profiles and cluster
- directories.
- """
-
- def __init__(self):
- self.async_cc = AsyncClientConnector()
-
- def get_task_client(self, profile='default', cluster_dir=None,
- furl_or_file=None, ipython_dir=None,
- delay=DELAY, max_tries=MAX_TRIES):
- """Get the task client.
-
- Usually only the ``profile`` option will be needed. If a FURL file
- can't be found by its profile, use ``cluster_dir`` or
- ``furl_or_file``.
-
- Parameters
- ----------
- profile : str
- The name of a cluster directory profile (default="default"). The
- cluster directory "cluster_<profile>" will be searched for
- in ``os.getcwd()``, the ipython_dir and then in the directories
- listed in the :env:`IPCLUSTER_DIR_PATH` environment variable.
- cluster_dir : str
- The full path to a cluster directory. This is useful if profiles
- are not being used.
- furl_or_file : str
- A furl or a filename containing a FURL. This is useful if you
- simply know the location of the FURL file.
- ipython_dir : str
- The location of the ipython_dir if different from the default.
- This is used if the cluster directory is being found by profile.
- delay : float
- The initial delay between re-connection attempts. Susequent delays
- get longer according to ``delay[i] = 1.5*delay[i-1]``.
- max_tries : int
- The max number of re-connection attempts.
-
- Returns
- -------
- The task client instance.
- """
- client = blockingCallFromThread(
- self.async_cc.get_task_client, profile, cluster_dir,
- furl_or_file, ipython_dir, delay, max_tries
- )
- return client.adapt_to_blocking_client()
-
- def get_multiengine_client(self, profile='default', cluster_dir=None,
- furl_or_file=None, ipython_dir=None,
- delay=DELAY, max_tries=MAX_TRIES):
- """Get the multiengine client.
-
- Usually only the ``profile`` option will be needed. If a FURL file
- can't be found by its profile, use ``cluster_dir`` or
- ``furl_or_file``.
-
- Parameters
- ----------
- profile : str
- The name of a cluster directory profile (default="default"). The
- cluster directory "cluster_<profile>" will be searched for
- in ``os.getcwd()``, the ipython_dir and then in the directories
- listed in the :env:`IPCLUSTER_DIR_PATH` environment variable.
- cluster_dir : str
- The full path to a cluster directory. This is useful if profiles
- are not being used.
- furl_or_file : str
- A furl or a filename containing a FURL. This is useful if you
- simply know the location of the FURL file.
- ipython_dir : str
- The location of the ipython_dir if different from the default.
- This is used if the cluster directory is being found by profile.
- delay : float
- The initial delay between re-connection attempts. Susequent delays
- get longer according to ``delay[i] = 1.5*delay[i-1]``.
- max_tries : int
- The max number of re-connection attempts.
-
- Returns
- -------
- The multiengine client instance.
- """
- client = blockingCallFromThread(
- self.async_cc.get_multiengine_client, profile, cluster_dir,
- furl_or_file, ipython_dir, delay, max_tries
- )
- return client.adapt_to_blocking_client()
-
- def get_client(self, profile='default', cluster_dir=None,
- furl_or_file=None, ipython_dir=None,
- delay=DELAY, max_tries=MAX_TRIES):
- client = blockingCallFromThread(
- self.async_cc.get_client, profile, cluster_dir,
- furl_or_file, ipython_dir,
- delay, max_tries
- )
- return client.adapt_to_blocking_client()
-
-
-class ClusterStateError(Exception):
- pass
-
-
-class AsyncCluster(object):
- """An class that wraps the :command:`ipcluster` script."""
-
- def __init__(self, profile='default', cluster_dir=None, ipython_dir=None,
- auto_create=False, auto_stop=True):
- """Create a class to manage an IPython cluster.
-
- This class calls the :command:`ipcluster` command with the right
- options to start an IPython cluster. Typically a cluster directory
- must be created (:command:`ipcluster create`) and configured before
- using this class. Configuration is done by editing the
- configuration files in the top level of the cluster directory.
-
- Parameters
- ----------
- profile : str
- The name of a cluster directory profile (default="default"). The
- cluster directory "cluster_<profile>" will be searched for
- in ``os.getcwd()``, the ipython_dir and then in the directories
- listed in the :env:`IPCLUSTER_DIR_PATH` environment variable.
- cluster_dir : str
- The full path to a cluster directory. This is useful if profiles
- are not being used.
- ipython_dir : str
- The location of the ipython_dir if different from the default.
- This is used if the cluster directory is being found by profile.
- auto_create : bool
- Automatically create the cluster directory it is dones't exist.
- This will usually only make sense if using a local cluster
- (default=False).
- auto_stop : bool
- Automatically stop the cluster when this instance is garbage
- collected (default=True). This is useful if you want the cluster
- to live beyond your current process. There is also an instance
- attribute ``auto_stop`` to change this behavior.
- """
- self._setup_cluster_dir(profile, cluster_dir, ipython_dir, auto_create)
- self.state = 'before'
- self.launcher = None
- self.client_connector = None
- self.auto_stop = auto_stop
-
- def __del__(self):
- if self.auto_stop and self.state=='running':
- print "Auto stopping the cluster..."
- self.stop()
-
- @property
- def location(self):
- if hasattr(self, 'cluster_dir_obj'):
- return self.cluster_dir_obj.location
- else:
- return ''
-
- @property
- def running(self):
- if self.state=='running':
- return True
- else:
- return False
-
- def _setup_cluster_dir(self, profile, cluster_dir, ipython_dir, auto_create):
- if ipython_dir is None:
- ipython_dir = get_ipython_dir()
- if cluster_dir is not None:
- try:
- self.cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir)
- except ClusterDirError:
- pass
- if profile is not None:
- try:
- self.cluster_dir_obj = ClusterDir.find_cluster_dir_by_profile(
- ipython_dir, profile)
- except ClusterDirError:
- pass
- if auto_create or profile=='default':
- # This should call 'ipcluster create --profile default
- self.cluster_dir_obj = ClusterDir.create_cluster_dir_by_profile(
- ipython_dir, profile)
- else:
- raise ClusterDirError('Cluster dir not found.')
-
- @make_deferred
- def start(self, n=2):
- """Start the IPython cluster with n engines.
-
- Parameters
- ----------
- n : int
- The number of engine to start.
- """
- # We might want to add logic to test if the cluster has started
- # by another process....
- if not self.state=='running':
- self.launcher = IPClusterLauncher(os.getcwd())
- self.launcher.ipcluster_n = n
- self.launcher.ipcluster_subcommand = 'start'
- d = self.launcher.start()
- d.addCallback(self._handle_start)
- return d
- else:
- raise ClusterStateError('Cluster is already running')
-
- @make_deferred
- def stop(self):
- """Stop the IPython cluster if it is running."""
- if self.state=='running':
- d1 = self.launcher.observe_stop()
- d1.addCallback(self._handle_stop)
- d2 = self.launcher.stop()
- return gatherBoth([d1, d2], consumeErrors=True)
- else:
- raise ClusterStateError("Cluster not running")
-
- def get_multiengine_client(self, delay=DELAY, max_tries=MAX_TRIES):
- """Get the multiengine client for the running cluster.
-
- If this fails, it means that the cluster has not finished starting.
- Usually waiting a few seconds are re-trying will solve this.
- """
- if self.client_connector is None:
- self.client_connector = AsyncClientConnector()
- return self.client_connector.get_multiengine_client(
- cluster_dir=self.cluster_dir_obj.location,
- delay=delay, max_tries=max_tries
- )
-
- def get_task_client(self, delay=DELAY, max_tries=MAX_TRIES):
- """Get the task client for the running cluster.
-
- If this fails, it means that the cluster has not finished starting.
- Usually waiting a few seconds are re-trying will solve this.
- """
- if self.client_connector is None:
- self.client_connector = AsyncClientConnector()
- return self.client_connector.get_task_client(
- cluster_dir=self.cluster_dir_obj.location,
- delay=delay, max_tries=max_tries
- )
-
- def get_ipengine_logs(self):
- return self.get_logs_by_name('ipengine')
-
- def get_ipcontroller_logs(self):
- return self.get_logs_by_name('ipcontroller')
-
- def get_ipcluster_logs(self):
- return self.get_logs_by_name('ipcluster')
-
- def get_logs_by_name(self, name='ipcluster'):
- log_dir = self.cluster_dir_obj.log_dir
- logs = {}
- for log in os.listdir(log_dir):
- if log.startswith(name + '-') and log.endswith('.log'):
- with open(os.path.join(log_dir, log), 'r') as f:
- logs[log] = f.read()
- return logs
-
- def get_logs(self):
- d = self.get_ipcluster_logs()
- d.update(self.get_ipengine_logs())
- d.update(self.get_ipcontroller_logs())
- return d
-
- def _handle_start(self, r):
- self.state = 'running'
-
- def _handle_stop(self, r):
- self.state = 'after'
-
-
-class Cluster(object):
-
-
- def __init__(self, profile='default', cluster_dir=None, ipython_dir=None,
- auto_create=False, auto_stop=True):
- """Create a class to manage an IPython cluster.
-
- This class calls the :command:`ipcluster` command with the right
- options to start an IPython cluster. Typically a cluster directory
- must be created (:command:`ipcluster create`) and configured before
- using this class. Configuration is done by editing the
- configuration files in the top level of the cluster directory.
-
- Parameters
- ----------
- profile : str
- The name of a cluster directory profile (default="default"). The
- cluster directory "cluster_<profile>" will be searched for
- in ``os.getcwd()``, the ipython_dir and then in the directories
- listed in the :env:`IPCLUSTER_DIR_PATH` environment variable.
- cluster_dir : str
- The full path to a cluster directory. This is useful if profiles
- are not being used.
- ipython_dir : str
- The location of the ipython_dir if different from the default.
- This is used if the cluster directory is being found by profile.
- auto_create : bool
- Automatically create the cluster directory it is dones't exist.
- This will usually only make sense if using a local cluster
- (default=False).
- auto_stop : bool
- Automatically stop the cluster when this instance is garbage
- collected (default=True). This is useful if you want the cluster
- to live beyond your current process. There is also an instance
- attribute ``auto_stop`` to change this behavior.
- """
- self.async_cluster = AsyncCluster(
- profile, cluster_dir, ipython_dir, auto_create, auto_stop
- )
- self.cluster_dir_obj = self.async_cluster.cluster_dir_obj
- self.client_connector = None
-
- def _set_auto_stop(self, value):
- self.async_cluster.auto_stop = value
-
- def _get_auto_stop(self):
- return self.async_cluster.auto_stop
-
- auto_stop = property(_get_auto_stop, _set_auto_stop)
-
- @property
- def location(self):
- return self.async_cluster.location
-
- @property
- def running(self):
- return self.async_cluster.running
-
- def start(self, n=2):
- """Start the IPython cluster with n engines.
-
- Parameters
- ----------
- n : int
- The number of engine to start.
- """
- return blockingCallFromThread(self.async_cluster.start, n)
-
- def stop(self):
- """Stop the IPython cluster if it is running."""
- return blockingCallFromThread(self.async_cluster.stop)
-
- def get_multiengine_client(self, delay=DELAY, max_tries=MAX_TRIES):
- """Get the multiengine client for the running cluster.
-
- This will try to attempt to the controller multiple times. If this
- fails altogether, try looking at the following:
- * Make sure the controller is starting properly by looking at its
- log files.
- * Make sure the controller is writing its FURL file in the location
- expected by the client.
- * Make sure a firewall on the controller's host is not blocking the
- client from connecting.
-
- Parameters
- ----------
- delay : float
- The initial delay between re-connection attempts. Susequent delays
- get longer according to ``delay[i] = 1.5*delay[i-1]``.
- max_tries : int
- The max number of re-connection attempts.
- """
- if self.client_connector is None:
- self.client_connector = ClientConnector()
- return self.client_connector.get_multiengine_client(
- cluster_dir=self.cluster_dir_obj.location,
- delay=delay, max_tries=max_tries
- )
-
- def get_task_client(self, delay=DELAY, max_tries=MAX_TRIES):
- """Get the task client for the running cluster.
-
- This will try to attempt to the controller multiple times. If this
- fails altogether, try looking at the following:
- * Make sure the controller is starting properly by looking at its
- log files.
- * Make sure the controller is writing its FURL file in the location
- expected by the client.
- * Make sure a firewall on the controller's host is not blocking the
- client from connecting.
-
- Parameters
- ----------
- delay : float
- The initial delay between re-connection attempts. Susequent delays
- get longer according to ``delay[i] = 1.5*delay[i-1]``.
- max_tries : int
- The max number of re-connection attempts.
- """
- if self.client_connector is None:
- self.client_connector = ClientConnector()
- return self.client_connector.get_task_client(
- cluster_dir=self.cluster_dir_obj.location,
- delay=delay, max_tries=max_tries
- )
-
- def __repr__(self):
- s = "<Cluster(running=%r, location=%s)" % (self.running, self.location)
- return s
-
- def get_logs_by_name(self, name='ipcluter'):
- """Get a dict of logs by process name (ipcluster, ipengine, etc.)"""
- return self.async_cluster.get_logs_by_name(name)
-
- def get_ipengine_logs(self):
- """Get a dict of logs for all engines in this cluster."""
- return self.async_cluster.get_ipengine_logs()
-
- def get_ipcontroller_logs(self):
- """Get a dict of logs for the controller in this cluster."""
- return self.async_cluster.get_ipcontroller_logs()
-
- def get_ipcluster_logs(self):
- """Get a dict of the ipcluster logs for this cluster."""
- return self.async_cluster.get_ipcluster_logs()
-
- def get_logs(self):
- """Get a dict of all logs for this cluster."""
- return self.async_cluster.get_logs()
-
- def _print_logs(self, logs):
- for k, v in logs.iteritems():
- print "==================================="
- print "Logfile: %s" % k
- print "==================================="
- print v
- print
-
- def print_ipengine_logs(self):
- """Print the ipengine logs for this cluster to stdout."""
- self._print_logs(self.get_ipengine_logs())
-
- def print_ipcontroller_logs(self):
- """Print the ipcontroller logs for this cluster to stdout."""
- self._print_logs(self.get_ipcontroller_logs())
-
- def print_ipcluster_logs(self):
- """Print the ipcluster logs for this cluster to stdout."""
- self._print_logs(self.get_ipcluster_logs())
-
- def print_logs(self):
- """Print all the logs for this cluster to stdout."""
- self._print_logs(self.get_logs())
-
View
32 IPython/kernel/clientinterfaces.py
@@ -1,32 +0,0 @@
-# encoding: utf-8
-
-"""General client interfaces."""
-
-__docformat__ = "restructuredtext en"
-
-#-------------------------------------------------------------------------------
-# Copyright (C) 2008 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
-#-------------------------------------------------------------------------------
-
-from zope.interface import Interface
-
-class IFCClientInterfaceProvider(Interface):
-
- def remote_get_client_name():
- """Return a string giving the class which implements a client-side interface.
-
- The client side of any foolscap connection initially gets a remote reference.
- Some class is needed to adapt that reference to an interface. This...
- """
-
-class IBlockingClientAdaptor(Interface):
-
- def adapt_to_blocking_client():
- """"""
View
538 IPython/kernel/clusterdir.py
@@ -1,538 +0,0 @@
-#!/usr/bin/env python
-# encoding: utf-8
-"""
-The IPython cluster directory
-"""
-
-#-----------------------------------------------------------------------------
-# 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
-#-----------------------------------------------------------------------------
-
-from __future__ import with_statement
-
-import os
-import shutil
-import sys
-import warnings
-
-from twisted.python import log
-
-from IPython.config.loader import PyFileConfigLoader
-from IPython.core.application import Application, BaseAppConfigLoader
-from IPython.config.configurable import Configurable
-from IPython.core.crashhandler import CrashHandler
-from IPython.core import release
-from IPython.utils.path import (
- get_ipython_package_dir,
- expand_path
-)
-from IPython.utils.traitlets import Unicode
-
-#-----------------------------------------------------------------------------
-# Warnings control
-#-----------------------------------------------------------------------------
-# Twisted generates annoying warnings with Python 2.6, as will do other code
-# that imports 'sets' as of today
-warnings.filterwarnings('ignore', 'the sets module is deprecated',
- DeprecationWarning )
-
-# This one also comes from Twisted
-warnings.filterwarnings('ignore', 'the sha module is deprecated',
- DeprecationWarning)
-
-#-----------------------------------------------------------------------------
-# Module errors
-#-----------------------------------------------------------------------------
-
-class ClusterDirError(Exception):
- pass
-
-
-class PIDFileError(Exception):
- pass
-
-
-#-----------------------------------------------------------------------------
-# Class for managing cluster directories
-#-----------------------------------------------------------------------------
-
-class ClusterDir(Configurable):
- """An object to manage the cluster directory and its resources.
-
- The cluster directory is used by :command:`ipcontroller`,
- :command:`ipcontroller` and :command:`ipcontroller` to manage the
- configuration, logging and security of these applications.
-
- This object knows how to find, create and manage these directories. This
- should be used by any code that want's to handle cluster directories.
- """
-
- security_dir_name = Unicode('security')
- log_dir_name = Unicode('log')
- pid_dir_name = Unicode('pid')
- security_dir = Unicode(u'')
- log_dir = Unicode(u'')
- pid_dir = Unicode(u'')
- location = Unicode(u'')
-
- def __init__(self, location=u''):
- super(ClusterDir, self).__init__(location=location)
-
- def _location_changed(self, name, old, new):
- if not os.path.isdir(new):
- os.makedirs(new)
- self.security_dir = os.path.join(new, self.security_dir_name)
- self.log_dir = os.path.join(new, self.log_dir_name)
- self.pid_dir = os.path.join(new, self.pid_dir_name)
- self.check_dirs()
-
- def _log_dir_changed(self, name, old, new):
- self.check_log_dir()
-
- def check_log_dir(self):
- if not os.path.isdir(self.log_dir):
- os.mkdir(self.log_dir)
-
- def _security_dir_changed(self, name, old, new):
- self.check_security_dir()
-
- def check_security_dir(self):
- if not os.path.isdir(self.security_dir):
- os.mkdir(self.security_dir, 0700)
- os.chmod(self.security_dir, 0700)
-
- def _pid_dir_changed(self, name, old, new):
- self.check_pid_dir()
-
- def check_pid_dir(self):
- if not os.path.isdir(self.pid_dir):
- os.mkdir(self.pid_dir, 0700)
- os.chmod(self.pid_dir, 0700)
-
- def check_dirs(self):
- self.check_security_dir()
- self.check_log_dir()
- self.check_pid_dir()
-
- def load_config_file(self, filename):
- """Load a config file from the top level of the cluster dir.
-
- Parameters
- ----------
- filename : unicode or str
- The filename only of the config file that must be located in
- the top-level of the cluster directory.
- """
- loader = PyFileConfigLoader(filename, self.location)
- return loader.load_config()
-
- def copy_config_file(self, config_file, path=None, overwrite=False):
- """Copy a default config file into the active cluster directory.
-
- Default configuration files are kept in :mod:`IPython.config.default`.
- This function moves these from that location to the working cluster
- directory.
- """
- if path is None:
- import IPython.config.default
- path = IPython.config.default.__file__.split(os.path.sep)[:-1]
- path = os.path.sep.join(path)
- src = os.path.join(path, config_file)
- dst = os.path.join(self.location, config_file)
- if not os.path.isfile(dst) or overwrite:
- shutil.copy(src, dst)
-
- def copy_all_config_files(self, path=None, overwrite=False):
- """Copy all config files into the active cluster directory."""
- for f in [u'ipcontroller_config.py', u'ipengine_config.py',
- u'ipcluster_config.py']:
- self.copy_config_file(f, path=path, overwrite=overwrite)
-
- @classmethod
- def create_cluster_dir(csl, cluster_dir):
- """Create a new cluster directory given a full path.
-
- Parameters
- ----------
- cluster_dir : str
- The full path to the cluster directory. If it does exist, it will
- be used. If not, it will be created.
- """
- return ClusterDir(location=cluster_dir)
-
- @classmethod
- def create_cluster_dir_by_profile(cls, path, profile=u'default'):
- """Create a cluster dir by profile name and path.
-
- Parameters
- ----------
- path : str
- The path (directory) to put the cluster directory in.
- profile : str
- The name of the profile. The name of the cluster directory will
- be "cluster_<profile>".
- """
- if not os.path.isdir(path):
- raise ClusterDirError('Directory not found: %s' % path)
- cluster_dir = os.path.join(path, u'cluster_' + profile)
- return ClusterDir(location=cluster_dir)
-
- @classmethod
- def find_cluster_dir_by_profile(cls, ipython_dir, profile=u'default'):
- """Find an existing cluster dir by profile name, return its ClusterDir.
-
- This searches through a sequence of paths for a cluster dir. If it
- is not found, a :class:`ClusterDirError` exception will be raised.
-
- The search path algorithm is:
- 1. ``os.getcwd()``
- 2. ``ipython_dir``
- 3. The directories found in the ":" separated
- :env:`IPCLUSTER_DIR_PATH` environment variable.
-
- Parameters
- ----------
- ipython_dir : unicode or str
- The IPython directory to use.
- profile : unicode or str
- The name of the profile. The name of the cluster directory
- will be "cluster_<profile>".
- """
- dirname = u'cluster_' + profile
- cluster_dir_paths = os.environ.get('IPCLUSTER_DIR_PATH','')
- if cluster_dir_paths:
- cluster_dir_paths = cluster_dir_paths.split(':')
- else:
- cluster_dir_paths = []
- paths = [os.getcwd(), ipython_dir] + cluster_dir_paths
- for p in paths:
- cluster_dir = os.path.join(p, dirname)
- if os.path.isdir(cluster_dir):
- return ClusterDir(location=cluster_dir)
- else:
- raise ClusterDirError('Cluster directory not found in paths: %s' % dirname)
-
- @classmethod
- def find_cluster_dir(cls, cluster_dir):
- """Find/create a cluster dir and return its ClusterDir.
-
- This will create the cluster directory if it doesn't exist.
-
- Parameters
- ----------
- cluster_dir : unicode or str
- The path of the cluster directory. This is expanded using
- :func:`IPython.utils.genutils.expand_path`.
- """
- cluster_dir = expand_path(cluster_dir)
- if not os.path.isdir(cluster_dir):
- raise ClusterDirError('Cluster directory not found: %s' % cluster_dir)
- return ClusterDir(location=cluster_dir)
-
-
-#-----------------------------------------------------------------------------
-# Command line options
-#-----------------------------------------------------------------------------
-
-class ClusterDirConfigLoader(BaseAppConfigLoader):
-
- def _add_cluster_profile(self, parser):
- paa = parser.add_argument
- paa('-p', '--profile',
- dest='Global.profile',type=unicode,
- help=
- """The string name of the profile to be used. This determines the name
- of the cluster dir as: cluster_<profile>. The default profile is named
- 'default'. The cluster directory is resolve this way if the
- --cluster-dir option is not used.""",
- metavar='Global.profile')
-
- def _add_cluster_dir(self, parser):
- paa = parser.add_argument
- paa('--cluster-dir',
- dest='Global.cluster_dir',type=unicode,
- help="""Set the cluster dir. This overrides the logic used by the
- --profile option.""",
- metavar='Global.cluster_dir')
-
- def _add_work_dir(self, parser):
- paa = parser.add_argument
- paa('--work-dir',
- dest='Global.work_dir',type=unicode,
- help='Set the working dir for the process.',
- metavar='Global.work_dir')
-
- def _add_clean_logs(self, parser):
- paa = parser.add_argument
- paa('--clean-logs',
- dest='Global.clean_logs', action='store_true',
- help='Delete old log flies before starting.')
-
- def _add_no_clean_logs(self, parser):
- paa = parser.add_argument
- paa('--no-clean-logs',
- dest='Global.clean_logs', action='store_false',
- help="Don't Delete old log flies before starting.")
-
- def _add_arguments(self):
- super(ClusterDirConfigLoader, self)._add_arguments()
- self._add_cluster_profile(self.parser)
- self._add_cluster_dir(self.parser)
- self._add_work_dir(self.parser)
- self._add_clean_logs(self.parser)
- self._add_no_clean_logs(self.parser)
-
-
-#-----------------------------------------------------------------------------
-# Crash handler for this application
-#-----------------------------------------------------------------------------
-
-
-_message_template = """\
-Oops, $self.app_name crashed. We do our best to make it stable, but...
-
-A crash report was automatically generated with the following information:
- - A verbatim copy of the crash traceback.
- - Data on your current $self.app_name configuration.
-
-It was left in the file named:
-\t'$self.crash_report_fname'
-If you can email this file to the developers, the information in it will help
-them in understanding and correcting the problem.
-
-You can mail it to: $self.contact_name at $self.contact_email
-with the subject '$self.app_name Crash Report'.
-
-If you want to do it now, the following command will work (under Unix):
-mail -s '$self.app_name Crash Report' $self.contact_email < $self.crash_report_fname
-
-To ensure accurate tracking of this issue, please file a report about it at:
-$self.bug_tracker
-"""
-
-class ClusterDirCrashHandler(CrashHandler):
- """sys.excepthook for IPython itself, leaves a detailed report on disk."""
-
- message_template = _message_template
-
- def __init__(self, app):
- contact_name = release.authors['Brian'][0]
- contact_email = release.authors['Brian'][1]
- bug_tracker = 'http://github.com/ipython/ipython/issues'
- super(ClusterDirCrashHandler,self).__init__(
- app, contact_name, contact_email, bug_tracker
- )
-
-
-#-----------------------------------------------------------------------------
-# Main application
-#-----------------------------------------------------------------------------
-
-class ApplicationWithClusterDir(Application):
- """An application that puts everything into a cluster directory.
-
- Instead of looking for things in the ipython_dir, this type of application
- will use its own private directory called the "cluster directory"
- for things like config files, log files, etc.
-
- The cluster directory is resolved as follows:
-
- * If the ``--cluster-dir`` option is given, it is used.
- * If ``--cluster-dir`` is not given, the application directory is
- resolve using the profile name as ``cluster_<profile>``. The search
- path for this directory is then i) cwd if it is found there
- and ii) in ipython_dir otherwise.
-
- The config file for the application is to be put in the cluster
- dir and named the value of the ``config_file_name`` class attribute.
- """
-
- command_line_loader = ClusterDirConfigLoader
- crash_handler_class = ClusterDirCrashHandler
- auto_create_cluster_dir = True
-
- def create_default_config(self):
- super(ApplicationWithClusterDir, self).create_default_config()
- self.default_config.Global.profile = u'default'
- self.default_config.Global.cluster_dir = u''
- self.default_config.Global.work_dir = os.getcwd()
- self.default_config.Global.log_to_file = False
- self.default_config.Global.clean_logs = False
-
- def find_resources(self):
- """This resolves the cluster directory.
-
- This tries to find the cluster directory and if successful, it will
- have done:
- * Sets ``self.cluster_dir_obj`` to the :class:`ClusterDir` object for
- the application.
- * Sets ``self.cluster_dir`` attribute of the application and config
- objects.
-
- The algorithm used for this is as follows:
- 1. Try ``Global.cluster_dir``.
- 2. Try using ``Global.profile``.
- 3. If both of these fail and ``self.auto_create_cluster_dir`` is
- ``True``, then create the new cluster dir in the IPython directory.
- 4. If all fails, then raise :class:`ClusterDirError`.
- """
-
- try:
- cluster_dir = self.command_line_config.Global.cluster_dir
- except AttributeError:
- cluster_dir = self.default_config.Global.cluster_dir
- cluster_dir = expand_path(cluster_dir)
- try:
- self.cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir)
- except ClusterDirError:
- pass
- else:
- self.log.info('Using existing cluster dir: %s' % \
- self.cluster_dir_obj.location
- )
- self.finish_cluster_dir()
- return
-
- try:
- self.profile = self.command_line_config.Global.profile
- except AttributeError:
- self.profile = self.default_config.Global.profile
- try:
- self.cluster_dir_obj = ClusterDir.find_cluster_dir_by_profile(
- self.ipython_dir, self.profile)
- except ClusterDirError:
- pass
- else:
- self.log.info('Using existing cluster dir: %s' % \
- self.cluster_dir_obj.location
- )
- self.finish_cluster_dir()
- return
-
- if self.auto_create_cluster_dir:
- self.cluster_dir_obj = ClusterDir.create_cluster_dir_by_profile(
- self.ipython_dir, self.profile
- )
- self.log.info('Creating new cluster dir: %s' % \
- self.cluster_dir_obj.location
- )
- self.finish_cluster_dir()
- else:
- raise ClusterDirError('Could not find a valid cluster directory.')
-
- def finish_cluster_dir(self):
- # Set the cluster directory
- self.cluster_dir = self.cluster_dir_obj.location
-
- # These have to be set because they could be different from the one
- # that we just computed. Because command line has the highest
- # priority, this will always end up in the master_config.
- self.default_config.Global.cluster_dir = self.cluster_dir
- self.command_line_config.Global.cluster_dir = self.cluster_dir
-
- def find_config_file_name(self):
- """Find the config file name for this application."""
- # For this type of Application it should be set as a class attribute.
- if not hasattr(self, 'default_config_file_name'):
- self.log.critical("No config filename found")
- else:
- self.config_file_name = self.default_config_file_name
-
- def find_config_file_paths(self):
- # Set the search path to to the cluster directory. We should NOT
- # include IPython.config.default here as the default config files
- # are ALWAYS automatically moved to the cluster directory.
- conf_dir = os.path.join(get_ipython_package_dir(), 'config', 'default')
- self.config_file_paths = (self.cluster_dir,)
-
- def pre_construct(self):
- # The log and security dirs were set earlier, but here we put them
- # into the config and log them.
- config = self.master_config
- sdir = self.cluster_dir_obj.security_dir
- self.security_dir = config.Global.security_dir = sdir
- ldir = self.cluster_dir_obj.log_dir
- self.log_dir = config.Global.log_dir = ldir
- pdir = self.cluster_dir_obj.pid_dir
- self.pid_dir = config.Global.pid_dir = pdir
- self.log.info("Cluster directory set to: %s" % self.cluster_dir)
- config.Global.work_dir = unicode(expand_path(config.Global.work_dir))
- # Change to the working directory. We do this just before construct
- # is called so all the components there have the right working dir.
- self.to_work_dir()
-
- def to_work_dir(self):
- wd = self.master_config.Global.work_dir
- if unicode(wd) != unicode(os.getcwd()):
- os.chdir(wd)
- self.log.info("Changing to working dir: %s" % wd)
-
- def start_logging(self):
- # Remove old log files
- if self.master_config.Global.clean_logs:
- log_dir = self.master_config.Global.log_dir
- for f in os.listdir(log_dir):
- if f.startswith(self.name + u'-') and f.endswith('.log'):
- os.remove(os.path.join(log_dir, f))
- # Start logging to the new log file
- if self.master_config.Global.log_to_file:
- log_filename = self.name + u'-' + str(os.getpid()) + u'.log'
- logfile = os.path.join(self.log_dir, log_filename)
- open_log_file = open(logfile, 'w')
- else:
- open_log_file = sys.stdout
- log.startLogging(open_log_file)
-
- def write_pid_file(self, overwrite=False):
- """Create a .pid file in the pid_dir with my pid.
-
- This must be called after pre_construct, which sets `self.pid_dir`.
- This raises :exc:`PIDFileError` if the pid file exists already.
- """
- pid_file = os.path.join(self.pid_dir, self.name + u'.pid')
- if os.path.isfile(pid_file):
- pid = self.get_pid_from_file()
- if not overwrite:
- raise PIDFileError(
- 'The pid file [%s] already exists. \nThis could mean that this '
- 'server is already running with [pid=%s].' % (pid_file, pid)
- )
- with open(pid_file, 'w') as f:
- self.log.info("Creating pid file: %s" % pid_file)
- f.write(repr(os.getpid())+'\n')
-
- def remove_pid_file(self):
- """Remove the pid file.
-
- This should be called at shutdown by registering a callback with
- :func:`reactor.addSystemEventTrigger`. This needs to return
- ``None``.
- """
- pid_file = os.path.join(self.pid_dir, self.name + u'.pid')
- if os.path.isfile(pid_file):
- try:
- self.log.info("Removing pid file: %s" % pid_file)
- os.remove(pid_file)
- except:
- self.log.warn("Error removing the pid file: %s" % pid_file)
-
- def get_pid_from_file(self):
- """Get the pid from the pid file.
-
- If the pid file doesn't exist a :exc:`PIDFileError` is raised.
- """
- pid_file = os.path.join(self.pid_dir, self.name + u'.pid')
- if os.path.isfile(pid_file):
- with open(pid_file, 'r') as f:
- pid = int(f.read().strip())
- return pid
- else:
- raise PIDFileError('pid file not found: %s' % pid_file)
-
View
39 IPython/kernel/codeutil.py
@@ -1,39 +0,0 @@
-# encoding: utf-8
-
-"""Utilities to enable code objects to be pickled.
-
-Any process that import this module will be able to pickle code objects. This
-includes the func_code attribute of any function. Once unpickled, new
-functions can be built using new.function(code, globals()). Eventually
-we need to automate all of this so that functions themselves can be pickled.
-
-Reference: A. Tremols, P Cogolo, "Python Cookbook," p 302-305
-"""
-
-__docformat__ = "restructuredtext en"
-
-#-------------------------------------------------------------------------------
-# Copyright (C) 2008 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 new, types, copy_reg
-
-def code_ctor(*args):
- return new.code(*args)
-
-def reduce_code(co):
- if co.co_freevars or co.co_cellvars:
- raise ValueError("Sorry, cannot pickle code objects with closures")
- return code_ctor, (co.co_argcount, co.co_nlocals, co.co_stacksize,
- co.co_flags, co.co_code, co.co_consts, co.co_names,
- co.co_varnames, co.co_filename, co.co_name, co.co_firstlineno,
- co.co_lnotab)
-
-copy_reg.pickle(types.CodeType, reduce_code)
View
79 IPython/kernel/configobjfactory.py
@@ -1,79 +0,0 @@
-#!/usr/bin/env python
-# encoding: utf-8
-"""
-A class for creating a Twisted service that is configured using IPython's
-configuration system.
-"""
-
-#-----------------------------------------------------------------------------
-# 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 zope.interface as zi
-
-from IPython.config.configurable import Configurable
-
-#-----------------------------------------------------------------------------
-# Code
-#-----------------------------------------------------------------------------
-
-
-class IConfiguredObjectFactory(zi.Interface):
- """I am a component that creates a configured object.
-
- This class is useful if you want to configure a class that is not a
- subclass of :class:`IPython.config.configurable.Configurable`.
- """
-
- def __init__(config=None):
- """Get ready to configure the object using config."""
-
- def create():
- """Return an instance of the configured object."""
-
-
-class ConfiguredObjectFactory(Configurable):
-
- zi.implements(IConfiguredObjectFactory)
-
- def __init__(self, config=None):
- super(ConfiguredObjectFactory, self).__init__(config=config)
-
- def create(self):
- raise NotImplementedError('create must be implemented in a subclass')
-
-
-class IAdaptedConfiguredObjectFactory(zi.Interface):
- """I am a component that adapts and configures an object.
-
- This class is useful if you have the adapt an instance and configure it.
- """
-
- def __init__(config=None, adaptee=None):
- """Get ready to adapt adaptee and then configure it using config."""
-
- def create():
- """Return an instance of the adapted and configured object."""
-
-
-class AdaptedConfiguredObjectFactory(Configurable):
-
- # zi.implements(IAdaptedConfiguredObjectFactory)
-
- def __init__(self, config=None, adaptee=None):
- # print
- # print "config pre:", config
- super(AdaptedConfiguredObjectFactory, self).__init__(config=config)
- # print
- # print "config post:", config
- self.adaptee = adaptee
-
- def create(self):
- raise NotImplementedError('create must be implemented in a subclass')
View
374 IPython/kernel/controllerservice.py
@@ -1,374 +0,0 @@
-# encoding: utf-8
-# -*- test-case-name: IPython.kernel.test.test_controllerservice -*-
-
-"""A Twisted Service for the IPython Controller.
-
-The IPython Controller:
-
-* Listens for Engines to connect and then manages access to those engines.
-* Listens for clients and passes commands from client to the Engines.
-* Exposes an asynchronous interfaces to the Engines which themselves can block.
-* Acts as a gateway to the Engines.
-
-The design of the controller is somewhat abstract to allow flexibility in how
-the controller is presented to clients. This idea is that there is a basic
-ControllerService class that allows engines to connect to it. But, this
-basic class has no client interfaces. To expose client interfaces developers
-provide an adapter that makes the ControllerService look like something. For
-example, one client interface might support task farming and another might
-support interactive usage. The important thing is that by using interfaces
-and adapters, a single controller can be accessed from multiple interfaces.
-Furthermore, by adapting various client interfaces to various network
-protocols, each client interface can be exposed to multiple network protocols.
-See multiengine.py for an example of how to adapt the ControllerService
-to a client interface.
-"""
-
-__docformat__ = "restructuredtext en"
-
-#-------------------------------------------------------------------------------
-# Copyright (C) 2008 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 os
-
-from twisted.application import service
-from twisted.python import log
-from zope.interface import Interface, implements, Attribute
-
-from IPython.kernel.engineservice import \
- IEngineCore, \
- IEngineSerialized, \
- IEngineQueued
-
-from IPython.utils.path import get_ipython_dir
-from IPython.kernel import codeutil
-
-#-------------------------------------------------------------------------------
-# Interfaces for the Controller
-#-------------------------------------------------------------------------------
-
-class IControllerCore(Interface):
- """Basic methods any controller must have.
-
- This is basically the aspect of the controller relevant to the
- engines and does not assume anything about how the engines will
- be presented to a client.
- """
-
- engines = Attribute("A dict of engine ids and engine instances.")
-
- def register_engine(remoteEngine, id=None, ip=None, port=None,
- pid=None):
- """Register new remote engine.
-
- The controller can use the ip, port, pid of the engine to do useful things
- like kill the engines.
-
- :Parameters:
- remoteEngine
- An implementer of IEngineCore, IEngineSerialized and IEngineQueued.
- id : int
- Requested id.
- ip : str
- IP address the engine is running on.
- port : int
- Port the engine is on.
- pid : int
- pid of the running engine.
-
- :Returns: A dict of {'id':id} and possibly other key, value pairs.
- """
-
- def unregister_engine(id):
- """Handle a disconnecting engine.
-
- :Parameters:
- id
- The integer engine id of the engine to unregister.
- """
-
- def on_register_engine_do(f, includeID, *args, **kwargs):
- """Call ``f(*args, **kwargs)`` when an engine is registered.
-
- :Parameters:
- includeID : int
- If True the first argument to f will be the id of the engine.
- """
-
- def on_unregister_engine_do(f, includeID, *args, **kwargs):
- """Call ``f(*args, **kwargs)`` when an engine is unregistered.
-
- :Parameters:
- includeID : int
- If True the first argument to f will be the id of the engine.
- """
-
- def on_register_engine_do_not(f):
- """Stop calling f on engine registration"""
-
- def on_unregister_engine_do_not(f):
- """Stop calling f on engine unregistration"""
-
- def on_n_engines_registered_do(n, f, *arg, **kwargs):
- """Call f(*args, **kwargs) the first time the nth engine registers."""
-
-class IControllerBase(IControllerCore):
- """The basic controller interface."""
- pass
-
-
-#-------------------------------------------------------------------------------
-# Implementation of the ControllerService
-#-------------------------------------------------------------------------------
-
-class ControllerService(object, service.Service):
- """A basic Controller represented as a Twisted Service.
-
- This class doesn't implement any client notification mechanism. That
- is up to adapted subclasses.
- """
-
- # I also pick up the IService interface by inheritance from service.Service
- implements(IControllerBase)
- name = 'ControllerService'
-
- def __init__(self, maxEngines=511, saveIDs=False):
- self.saveIDs = saveIDs
- self.engines = {}
- self.availableIDs = range(maxEngines,-1,-1) # [511,...,0]
- self._onRegister = []
- self._onUnregister = []
- self._onNRegistered = []
-
- #---------------------------------------------------------------------------
- # Methods used to save the engine info to a log file
- #---------------------------------------------------------------------------
-
- def _buildEngineInfoString(self, id, ip, port, pid):
- if id is None:
- id = -99
- if ip is None:
- ip = "-99"
- if port is None:
- port = -99
- if pid is None:
- pid = -99
- return "Engine Info: %d %s %d %d" % (id, ip , port, pid)
-
- def _logEngineInfo(self, id, ip, port, pid):
- log.msg(self._buildEngineInfoString(id,ip,port,pid))
-
- def _getEngineInfoLogFile(self):
- # Store all logs inside the ipython directory
- ipdir = 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
-
- def _logEngineInfoToFile(self, id, ip, port, pid):
- """Log info about an engine to a log file.
-
- When an engine registers with a ControllerService, the ControllerService
- saves information about the engine to a log file. That information
- can be useful for various purposes, such as killing hung engines, etc.
-
- This method takes the assigned id, ip/port and pid of the engine
- and saves it to a file of the form:
-
- IPYTHON_DIR/log/ipcontroller-###-engine-info.log
-
- where ### is the pid of the controller.
-
- Each line of this file has the form:
-
- Engine Info: ip ip port pid
-
- If any of the entries are not known, they are replaced by -99.
- """
-
- fname = self._getEngineInfoLogFile()
- f = open(fname, 'a')
- s = self._buildEngineInfoString(id,ip,port,pid)
- f.write(s + '\n')
- f.close()
-
- #---------------------------------------------------------------------------
- # IControllerCore methods
- #---------------------------------------------------------------------------
-
- def register_engine(self, remoteEngine, id=None,
- ip=None, port=None, pid=None):
- """Register new engine connection"""
-
- # What happens if these assertions fail?
- assert IEngineCore.providedBy(remoteEngine), \
- "engine passed to register_engine doesn't provide IEngineCore"
- assert IEngineSerialized.providedBy(remoteEngine), \
- "engine passed to register_engine doesn't provide IEngineSerialized"
- assert IEngineQueued.providedBy(remoteEngine), \
- "engine passed to register_engine doesn't provide IEngineQueued"
- assert isinstance(id, int) or id is None, \
- "id to register_engine must be an integer or None"
- assert isinstance(ip, str) or ip is None, \
- "ip to register_engine must be a string or None"
- assert isinstance(port, int) or port is None, \
- "port to register_engine must be an integer or None"
- assert isinstance(pid, int) or pid is None, \
- "pid to register_engine must be an integer or None"
-
- desiredID = id
- if desiredID in self.engines.keys():
- desiredID = None
-
- if desiredID in self.availableIDs:
- getID = desiredID
- self.availableIDs.remove(desiredID)
- else:
- getID = self.availableIDs.pop()
- remoteEngine.id = getID
- remoteEngine.service = self
- self.engines[getID] = remoteEngine
-
- # Log the Engine Information for monitoring purposes
- self._logEngineInfoToFile(getID, ip, port, pid)
-
- msg = "registered engine with id: %i" %getID
- log.msg(msg)
-
- for i in range(len(self._onRegister)):
- (f,args,kwargs,ifid) = self._onRegister[i]
- try:
- if ifid:
- f(getID, *args, **kwargs)
- else:
- f(*args, **kwargs)
- except:
- self._onRegister.pop(i)
-
- # Call functions when the nth engine is registered and them remove them
- for i, (n, f, args, kwargs) in enumerate(self._onNRegistered):
- if len(self.engines.keys()) == n:
- try:
- try:
- f(*args, **kwargs)
- except:
- log.msg("Function %r failed when the %ith engine registered" % (f, n))
- finally:
- self._onNRegistered.pop(i)
-
- return {'id':getID}
-
- def unregister_engine(self, id):
- """Unregister engine by id."""
-
- assert isinstance(id, int) or id is None, \
- "id to unregister_engine must be an integer or None"
-
- msg = "unregistered engine with id: %i" %id
- log.msg(msg)
- try:
- del self.engines[id]
- except KeyError:
- log.msg("engine with id %i was not registered" % id)
- else:
- if not self.saveIDs:
- self.availableIDs.append(id)
- # Sort to assign lower ids first
- self.availableIDs.sort(reverse=True)
- else:
- log.msg("preserving id %i" %id)
-
- for i in range(len(self._onUnregister)):
- (f,args,kwargs,ifid) = self._onUnregister[i]
- try:
- if ifid:
- f(id, *args, **kwargs)
- else:
- f(*args, **kwargs)
- except:
- self._onUnregister.pop(i)
-
- def on_register_engine_do(self, f, includeID, *args, **kwargs):
- assert callable(f), "f must be callable"
- self._onRegister.append((f,args,kwargs,includeID))
-
- def on_unregister_engine_do(self, f, includeID, *args, **kwargs):
- assert callable(f), "f must be callable"
- self._onUnregister.append((f,args,kwargs,includeID))
-
- def on_register_engine_do_not(self, f):
- for i in range(len(self._onRegister)):
- g = self._onRegister[i][0]
- if f == g:
- self._onRegister.pop(i)
- return
-
- def on_unregister_engine_do_not(self, f):
- for i in range(len(self._onUnregister)):
- g = self._onUnregister[i][0]
- if f == g:
- self._onUnregister.pop(i)
- return
-
- def on_n_engines_registered_do(self, n, f, *args, **kwargs):
- if len(self.engines.keys()) >= n:
- f(*args, **kwargs)
- else:
- self._onNRegistered.append((n,f,args,kwargs))
-
-
-#-------------------------------------------------------------------------------
-# Base class for adapting controller to different client APIs
-#-------------------------------------------------------------------------------
-
-class ControllerAdapterBase(object):
- """All Controller adapters should inherit from this class.
-
- This class provides a wrapped version of the IControllerBase interface that
- can be used to easily create new custom controllers. Subclasses of this
- will provide a full implementation of IControllerBase.
-
- This class doesn't implement any client notification mechanism. That
- is up to subclasses.
- """
-
- implements(IControllerBase)
-
- def __init__(self, controller):
- self.controller = controller
- # Needed for IControllerCore
- self.engines = self.controller.engines
-
- def register_engine(self, remoteEngine, id=None,
- ip=None, port=None, pid=None):
- return self.controller.register_engine(remoteEngine,
- id, ip, port, pid)
-
- def unregister_engine(self, id):
- return self.controller.unregister_engine(id)
-
- def on_register_engine_do(self, f, includeID, *args, **kwargs):
- return self.controller.on_register_engine_do(f, includeID, *args, **kwargs)
-
- def on_unregister_engine_do(self, f, includeID, *args, **kwargs):
- return self.controller.on_unregister_engine_do(f, includeID, *args, **kwargs)
-
- def on_register_engine_do_not(self, f):
- return self.controller.on_register_engine_do_not(f)
-
- def on_unregister_engine_do_not(self, f):
- return self.controller.on_unregister_engine_do_not(f)
-
- def on_n_engines_registered_do(self, n, f, *args, **kwargs):
- return self.controller.on_n_engines_registered_do(n, f, *args, **kwargs)
View
16 IPython/kernel/core/__init__.py
@@ -1,16 +0,0 @@
-# encoding: utf-8
-
-"""The IPython Core."""
-
-__docformat__ = "restructuredtext en"
-
-#-------------------------------------------------------------------------------
-# Copyright (C) 2008 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
-#-------------------------------------------------------------------------------
View
70 IPython/kernel/core/display_formatter.py
@@ -1,70 +0,0 @@
-# encoding: utf-8
-
-"""Objects for replacing sys.displayhook()."""
-
-__docformat__ = "restructuredtext en"
-
-#-------------------------------------------------------------------------------
-# Copyright (C) 2008 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
-#-------------------------------------------------------------------------------
-
-class IDisplayFormatter(object):
- """ Objects conforming to this interface will be responsible for formatting
- representations of objects that pass through sys.displayhook() during an
- interactive interpreter session.
- """
-
- # The kind of formatter.
- kind = 'display'
-
- # The unique identifier for this formatter.
- identifier = None
-
-
- def __call__(self, obj):
- """ Return a formatted representation of an object.
-
- Return None if one cannot return a representation in this format.
- """
-
- raise NotImplementedError
-
-
-class ReprDisplayFormatter(IDisplayFormatter):
- """ Return the repr() string representation of an object.
- """
-
- # The unique identifier for this formatter.
- identifier = 'repr'
-
-
- def __call__(self, obj):
- """ Return a formatted representation of an object.
- """
-
- return repr(obj)
-
-
-class PPrintDisplayFormatter(IDisplayFormatter):
- """ Return a pretty-printed string representation of an object.
- """
-
- # The unique identifier for this formatter.
- identifier = 'pprint'
-
-
- def __call__(self, obj):
- """ Return a formatted representation of an object.
- """
-
- import pprint
- return pprint.pformat(obj)
-
-
View
100 IPython/kernel/core/display_trap.py
@@ -1,100 +0,0 @@
-# encoding: utf-8
-
-"""Manager for replacing sys.displayhook()."""
-
-__docformat__ = "restructuredtext en"
-
-#-------------------------------------------------------------------------------
-# Copyright (C) 2008 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
-#-------------------------------------------------------------------------------
-
-# Standard library imports.
-import sys
-
-
-
-class DisplayTrap(object):
- """ Object to trap and format objects passing through sys.displayhook().
-
- This trap maintains two lists of callables: formatters and callbacks. The
- formatters take the *last* object that has gone through since the trap was
- set and returns a string representation. Callbacks are executed on *every*
- object that passes through the displayhook and does not return anything.
- """
-
- def __init__(self, formatters=None, callbacks=None):
- # A list of formatters to apply. Each should be an instance conforming
- # to the IDisplayFormatter interface.
- if formatters is None:
- formatters = []
- self.formatters = formatters
-
- # A list of callables, each of which should be executed *every* time an
- # object passes through sys.displayhook().
- if callbacks is None:
- callbacks = []
- self.callbacks = callbacks
-
- # The last object to pass through the displayhook.
- self.obj = None
-
- # The previous hook before we replace it.
- self.old_hook = None
-
- def hook(self, obj):
- """ This method actually implements the hook.
- """
-
- # Run through the list of callbacks and trigger all of them.
- for callback in self.callbacks:
- callback(obj)
-
- # Store the object for formatting.
- self.obj = obj
-
- def set(self):
- """ Set the hook.
- """
-
- if sys.displayhook is not self.hook:
- self.old_hook = sys.displayhook
- sys.displayhook = self.hook
-
- def unset(self):
- """ Unset the hook.
- """
-
- sys.displayhook = self.old_hook
-
- def clear(self):
- """ Reset the stored object.
- """
-
- self.obj = None
-
- def add_to_message(self, message):
- """ Add the formatted display of the objects to the message dictionary
- being returned from the interpreter to its listeners.
- """
-
- # If there was no displayed object (or simply None), then don't add
- # anything.
- if self.obj is None:
- return
-
- # Go through the list of formatters and let them add their formatting.
- display = {}
- for formatter in self.formatters:
- representation = formatter(self.obj)
- if representation is not None:
- display[formatter.identifier] = representation
-
- message['display'] = display
-
View
41 IPython/kernel/core/error.py
@@ -1,41 +0,0 @@
-# encoding: utf-8
-
-"""
-error.py
-
-We declare here a class hierarchy for all exceptions produced by IPython, in
-cases where we don't just raise one from the standard library.
-"""
-
-__docformat__ = "restructuredtext en"
-
-#-------------------------------------------------------------------------------
-# Copyright (C) 2008 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
-#-------------------------------------------------------------------------------
-
-
-class IPythonError(Exception):
- """Base exception that all of our exceptions inherit from.
-
- This can be raised by code that doesn't have any more specific
- information."""
-
- pass
-
-# Exceptions associated with the controller objects
-class ControllerError(IPythonError): pass
-
-class ControllerCreationError(ControllerError): pass
-
-
-# Exceptions associated with the Engines
-class EngineError(IPythonError): pass
-
-class EngineCreationError(EngineError): pass
View
81 IPython/kernel/core/fd_redirector.py
@@ -1,81 +0,0 @@
-# encoding: utf-8
-
-"""
-Stdout/stderr redirector, at the OS level, using file descriptors.
-
-This also works under windows.
-"""
-
-__docformat__ = "restructuredtext en"
-
-#-------------------------------------------------------------------------------
-# Copyright (C) 2008 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.
-#-------------------------------------------------------------------------------
-
-
-