home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) __docformat__ = 'restructuredtext en' import sys sys.path.insert(0, '') from optparse import OptionParser import os from twisted.application import service from twisted.internet import reactor from twisted.python import log from IPython.kernel.fcutil import Tub, UnauthenticatedTub from IPython.kernel.core.config import config_manager as core_config_manager from IPython.config.cutils import import_item from IPython.kernel.engineservice import EngineService from IPython.iplib import user_setup from IPython.genutils import get_ipython_dir, get_log_dir, get_security_dir if os.name == 'posix': rc_suffix = '' else: rc_suffix = '.ini' user_setup(get_ipython_dir(), rc_suffix, mode = 'install', interactive = False) get_log_dir() get_security_dir() from IPython.kernel.config import config_manager as kernel_config_manager from IPython.kernel.engineconnector import EngineConnector def start_engine(): global mpi, mpi kernel_config = kernel_config_manager.get_config_obj() core_config = core_config_manager.get_config_obj() mpikey = kernel_config['mpi']['default'] mpi_import_statement = kernel_config['mpi'].get(mpikey, None) if mpi_import_statement is not None: try: exec mpi_import_statement in globals() mpi = None else: mpi = None logfile = kernel_config['engine']['logfile'] if logfile: logfile = logfile + str(os.getpid()) + '.log' try: openLogFile = open(logfile, 'w') openLogFile = sys.stdout else: openLogFile = sys.stdout log.startLogging(openLogFile) shell_class = import_item(core_config['shell']['shell_class']) engine_service = EngineService(shell_class, mpi = mpi) shell_import_statement = core_config['shell']['import_statement'] if shell_import_statement: try: engine_service.execute(shell_import_statement) log.msg('Error running import_statement: %s' % shell_import_statement) main_service = service.MultiService() engine_service.setServiceParent(main_service) tub_service = Tub() tub_service.setServiceParent(main_service) main_service.startService() engine_connector = EngineConnector(tub_service) furl_file = kernel_config['engine']['furl_file'] log.msg('Using furl file: %s' % furl_file) def call_connect(engine_service, furl_file): d = engine_connector.connect_to_controller(engine_service, furl_file) def handle_error(f): print 'error connecting to controller:', f.getErrorMessage() reactor.callLater(0.1, reactor.stop) d.addErrback(handle_error) reactor.callWhenRunning(call_connect, engine_service, furl_file) reactor.run() def init_config(): parser = OptionParser('ipengine [options]\n\nStart an IPython engine.\n\nUse the IPYTHONDIR environment variable to change your IPython directory \nfrom the default of .ipython or _ipython. The log and security \nsubdirectories of your IPython directory will be used by this script \nfor log files and security files.') parser.add_option('--furl-file', type = 'string', dest = 'furl_file', help = 'The filename containing the FURL of the controller') parser.add_option('--mpi', type = 'string', dest = 'mpi', help = 'How to enable MPI (mpi4py, pytrilinos, or empty string to disable)') parser.add_option('-l', '--logfile', type = 'string', dest = 'logfile', help = 'log file name (default is stdout)') (options, args) = parser.parse_args() kernel_config = kernel_config_manager.get_config_obj() if options.furl_file is not None: kernel_config['engine']['furl_file'] = options.furl_file if options.logfile is not None: kernel_config['engine']['logfile'] = options.logfile if options.mpi is not None: kernel_config['mpi']['default'] = options.mpi def main(): init_config() start_engine() if __name__ == '__main__': main()