From e97da5b198e89a7806c39cdff2565a2c0975efba 2009-11-09 00:11:29 From: bgranger Date: 2009-11-09 00:11:29 Subject: [PATCH] Minors fixes on Windows. * Don't import daemonize if os.name=='posix'. * Allow the controller to overwrite old .pid files upon startup. This was needed because the Windows HPC job scheduler kills jobs in a way that the signal handlers are not being run. --- diff --git a/IPython/kernel/clusterdir.py b/IPython/kernel/clusterdir.py index 4ad8dc0..cae1c4b 100644 --- a/IPython/kernel/clusterdir.py +++ b/IPython/kernel/clusterdir.py @@ -414,7 +414,7 @@ class ApplicationWithClusterDir(Application): open_log_file = sys.stdout log.startLogging(open_log_file) - def write_pid_file(self): + 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`. @@ -423,9 +423,11 @@ class ApplicationWithClusterDir(Application): pid_file = os.path.join(self.pid_dir, self.name + '.pid') if os.path.isfile(pid_file): pid = self.get_pid_from_file() - raise PIDFileError( - 'The pid file [%s] already exists. \nThis could mean that this ' - 'server is already running with [pid=%s].' % (pid_file, pid)) + 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') @@ -442,7 +444,8 @@ class ApplicationWithClusterDir(Application): self.log.info("Removing pid file: %s" % pid_file) os.remove(pid_file) except: - pass + self.log.warn("Error removing the pid file: %s" % pid_file) + raise def get_pid_from_file(self): """Get the pid from the pid file. diff --git a/IPython/kernel/ipclusterapp.py b/IPython/kernel/ipclusterapp.py index 08aed1b..b4af002 100644 --- a/IPython/kernel/ipclusterapp.py +++ b/IPython/kernel/ipclusterapp.py @@ -20,7 +20,8 @@ import os import signal import sys -from twisted.scripts._twistd_unix import daemonize +if os.name=='posix': + from twisted.scripts._twistd_unix import daemonize from IPython.core import release from IPython.external import argparse diff --git a/IPython/kernel/ipcontrollerapp.py b/IPython/kernel/ipcontrollerapp.py index ca3750f..bae6ccc 100644 --- a/IPython/kernel/ipcontrollerapp.py +++ b/IPython/kernel/ipcontrollerapp.py @@ -246,7 +246,7 @@ class IPControllerApp(ApplicationWithClusterDir): def start_app(self): # Start the controller service and set things running self.main_service.startService() - self.write_pid_file() + self.write_pid_file(overwrite=True) reactor.addSystemEventTrigger('during','shutdown', self.remove_pid_file) reactor.run()