Repository: ipython/ipython

Issue:
startup_command specified in ipengine_config.py is not executed
This used to work in IPython 1.2.1 

To recreate from a clean setup (i.e. new virtualenv with IPython installed):
`ipython profile create testcluster --parallel`
edit `$HOME/.ipython/profile_newcluster/ipengine_config.py`  to modify one line to `c.IPEngineApp.startup_command = 'open(u"/tmp/IPtouch","a").close();'`
and set in `$HOME/.ipython/profile_newcluster/ipcluster_config.py` `c.IPClusterStart.controller_launcher_class = 'LocalControllerLauncher'` and `c.IPClusterStart.engine_launcher_class = 'LocalEngineSetLauncher'`.

Now  starting ipython: `ipcluster start --profile=testcluster --n 1 --log-level=DEBUG`
the log is as follows:

```
$ ipcluster start --profile=testcluster --n 1 --log-level=DEBUG
2014-05-07 14:46:49.876 [IPClusterStart] Config changed:
2014-05-07 14:46:49.876 [IPClusterStart] {'Application': {'log_level': u'DEBUG'}, 'BaseIPythonApplication': {'profile': u'testcluster'}, 'IPClusterStart': {'n': 1}}
2014-05-07 14:46:49.877 [IPClusterStart] IPYTHONDIR set to: $HOME/.ipython
2014-05-07 14:46:49.885 [IPClusterStart] Using existing profile dir: u'$HOME/.ipython/profile_testcluster'
2014-05-07 14:46:49.885 [IPClusterStart] Searching path [u'$HOME/.ipython/profile_testcluster', u'$HOME/.ipython/profile_testcluster'] for config files
2014-05-07 14:46:49.885 [IPClusterStart] Attempting to load config file: ipython_config.py
2014-05-07 14:46:49.886 [IPClusterStart] Loaded config file: $HOME/.ipython/profile_testcluster/ipython_config.py
2014-05-07 14:46:49.886 [IPClusterStart] Attempting to load config file: ipcluster_config.py
2014-05-07 14:46:49.887 [IPClusterStart] Loaded config file: $HOME/.ipython/profile_testcluster/ipcontroller_config.py
2014-05-07 14:46:49.887 [IPClusterStart] Attempting to load config file: ipcluster_config.py
2014-05-07 14:46:49.888 [IPClusterStart] Loaded config file: $HOME/.ipython/profile_testcluster/ipengine_config.py
2014-05-07 14:46:49.889 [IPClusterStart] Config changed:
2014-05-07 14:46:49.889 [IPClusterStart] {'Application': {'log_level': u'DEBUG'}, 'BaseIPythonApplication': {'profile': u'testcluster'}, 'IPEngineApp': {'startup_command': 'open(u"/tmp/IPtouch","a").close();'}, 'IPClusterStart': {'n': 1}}
2014-05-07 14:46:49.890 [IPClusterStart] Attempting to load config file: ipcluster_config.py
2014-05-07 14:46:49.891 [IPClusterStart] Loaded config file: $HOME/.ipython/profile_testcluster/ipcluster_config.py
2014-05-07 14:46:49.892 [IPClusterStart] Config changed:
2014-05-07 14:46:49.892 [IPClusterStart] {'Application': {'log_level': u'DEBUG'}, 'BaseIPythonApplication': {'profile': u'testcluster'}, 'IPEngineApp': {'startup_command': 'open(u"/tmp/IPtouch","a").close();'}, 'IPClusterStart': {'controller_launcher_class': 'LocalControllerLauncher', 'engine_launcher_class': 'LocalEngineSetLauncher', 'n': 1}}
2014-05-07 14:46:49.895 [IPClusterStart] Starting ipcluster with [daemon=False]
2014-05-07 14:46:49.896 [IPClusterStart] Creating pid file: $HOME/.ipython/profile_testcluster/pid/ipcluster.pid
2014-05-07 14:46:49.897 [IPClusterStart] Starting Controller with LocalControllerLauncher
2014-05-07 14:46:49.897 [IPClusterStart] Starting LocalControllerLauncher: ['$HOME/startupTest/env/bin/python', '-m', 'IPython.parallel.controller', '--profile-dir', u'$HOME/.ipython/profile_testcluster', '--cluster-id', u'', '--log-to-file', '--log-level=20']
2014-05-07 14:46:49.901 [IPClusterStart] Process '$HOME/startupTest/env/bin/python' started: 8650
2014-05-07 14:46:50.305 [IPClusterStart] 2014-05-07 14:46:50.305 [IPControllerApp] Using existing profile dir: u'$HOME/.ipython/profile_testcluster'
2014-05-07 14:46:50.635 [IPClusterStart] 2014-05-07 14:46:50.635 [scheduler] Scheduler started [leastload]
2014-05-07 14:46:50.896 [IPClusterStart] Starting 1 Engines with LocalEngineSetLauncher
2014-05-07 14:46:50.899 [IPClusterStart] Starting LocalEngineLauncher: ['$HOME/startupTest/env/bin/python', '-m', 'IPython.parallel.engine', '--profile-dir', u'$HOME/.ipython/profile_testcluster', '--cluster-id', u'', '--log-to-file', '--log-level=20']
2014-05-07 14:46:50.905 [IPClusterStart] Process '$HOME/startupTest/env/bin/python' started: 8669
2014-05-07 14:46:50.905 [IPClusterStart] Process 'engine set' started: [None]
2014-05-07 14:46:51.302 [IPClusterStart] 2014-05-07 14:46:51.302 [IPEngineApp] Using existing profile dir: u'$HOME/.ipython/profile_testcluster'
2014-05-07 14:47:20.905 [IPClusterStart] Engines appear to have started successfully
```

Its clear that the config file is properly read, as `startup_command` appears in the `config changed` lists. But the file `/tmp/IPtouch` has not been read.

I am happy to try and fix it myself - although I am not sure where to start looking!



Discussion:

Resolving patch:
diff --git a/IPython/parallel/apps/ipengineapp.py b/IPython/parallel/apps/ipengineapp.py
--- a/IPython/parallel/apps/ipengineapp.py
+++ b/IPython/parallel/apps/ipengineapp.py
@@ -320,16 +320,19 @@ def init_engine(self):
         
         exec_lines = []
         for app in ('IPKernelApp', 'InteractiveShellApp'):
-            if '%s.exec_lines' in config:
-                exec_lines = config.IPKernelApp.exec_lines = config[app].exec_lines
+            if '%s.exec_lines' % app in config:
+                exec_lines = config[app].exec_lines
                 break
         
         exec_files = []
         for app in ('IPKernelApp', 'InteractiveShellApp'):
-            if '%s.exec_files' in config:
-                exec_files = config.IPKernelApp.exec_files = config[app].exec_files
+            if '%s.exec_files' % app in config:
+                exec_files = config[app].exec_files
                 break
         
+        config.IPKernelApp.exec_lines = exec_lines
+        config.IPKernelApp.exec_files = exec_files
+        
         if self.startup_script:
             exec_files.append(self.startup_script)
         if self.startup_command:


Test patch: