##// END OF EJS Templates
scrub twisted/deferred references from launchers...
MinRK -
Show More
@@ -0,0 +1,26 b''
1 """daemonize function from twisted.scripts._twistd_unix."""
2
3 #-----------------------------------------------------------------------------
4 # Copyright (c) Twisted Matrix Laboratories.
5 # See Twisted's LICENSE for details.
6 # http://twistedmatrix.com/
7 #-----------------------------------------------------------------------------
8
9 import os, errno
10
11 def daemonize():
12 # See http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC16
13 if os.fork(): # launch child and...
14 os._exit(0) # kill off parent
15 os.setsid()
16 if os.fork(): # launch child and...
17 os._exit(0) # kill off parent again.
18 null = os.open('/dev/null', os.O_RDWR)
19 for i in range(3):
20 try:
21 os.dup2(null, i)
22 except OSError, e:
23 if e.errno != errno.EBADF:
24 raise
25 os.close(null)
26
@@ -34,6 +34,7 b' from zmq.eventloop import ioloop'
34 34 from IPython.config.application import Application, boolean_flag
35 35 from IPython.config.loader import Config
36 36 from IPython.core.newapplication import BaseIPythonApplication, ProfileDir
37 from IPython.utils.daemonize import daemonize
37 38 from IPython.utils.importstring import import_item
38 39 from IPython.utils.traitlets import Int, Unicode, Bool, CFloat, Dict, List
39 40
@@ -368,7 +369,6 b' class IPClusterEngines(BaseParallelApplication):'
368 369 # TODO: Get daemonize working on Windows or as a Windows Server.
369 370 if self.daemonize:
370 371 if os.name=='posix':
371 from twisted.scripts._twistd_unix import daemonize
372 372 daemonize()
373 373
374 374 dc = ioloop.DelayedCallback(self.start_engines, 0, self.loop)
@@ -468,7 +468,6 b' class IPClusterStart(IPClusterEngines):'
468 468 # TODO: Get daemonize working on Windows or as a Windows Server.
469 469 if self.daemonize:
470 470 if os.name=='posix':
471 from twisted.scripts._twistd_unix import daemonize
472 471 daemonize()
473 472
474 473 dc = ioloop.DelayedCallback(self.start_controller, 0, self.loop)
@@ -157,29 +157,20 b' class BaseLauncher(LoggingConfigurable):'
157 157 return False
158 158
159 159 def start(self):
160 """Start the process.
161
162 This must return a deferred that fires with information about the
163 process starting (like a pid, job id, etc.).
164 """
160 """Start the process."""
165 161 raise NotImplementedError('start must be implemented in a subclass')
166 162
167 163 def stop(self):
168 164 """Stop the process and notify observers of stopping.
169 165
170 This must return a deferred that fires with information about the
171 processing stopping, like errors that occur while the process is
172 attempting to be shut down. This deferred won't fire when the process
173 actually stops. To observe the actual process stopping, see
174 :func:`observe_stop`.
166 This method will return None immediately.
167 To observe the actual process stopping, see :meth:`on_stop`.
175 168 """
176 169 raise NotImplementedError('stop must be implemented in a subclass')
177 170
178 171 def on_stop(self, f):
179 """Get a deferred that will fire when the process stops.
180
181 The deferred will fire with data that contains information about
182 the exit status of the process.
172 """Register a callback to be called with this Launcher's stop_data
173 when the process actually finishes.
183 174 """
184 175 if self.state=='after':
185 176 return f(self.stop_data)
@@ -202,7 +193,7 b' class BaseLauncher(LoggingConfigurable):'
202 193 """Call this to trigger process stop actions.
203 194
204 195 This logs the process stopping and sets the state to 'after'. Call
205 this to trigger all the deferreds from :func:`observe_stop`."""
196 this to trigger callbacks registered via :meth:`on_stop`."""
206 197
207 198 self.log.info('Process %r stopped: %r' % (self.args[0], data))
208 199 self.stop_data = data
@@ -215,8 +206,6 b' class BaseLauncher(LoggingConfigurable):'
215 206 def signal(self, sig):
216 207 """Signal the process.
217 208
218 Return a semi-meaningless deferred after signaling the process.
219
220 209 Parameters
221 210 ----------
222 211 sig : str or int
@@ -247,7 +236,6 b' class LocalProcessLauncher(BaseLauncher):'
247 236 work_dir=work_dir, config=config, **kwargs
248 237 )
249 238 self.process = None
250 self.start_deferred = None
251 239 self.poller = None
252 240
253 241 def find_args(self):
@@ -520,7 +508,7 b' class MPIExecEngineSetLauncher(MPIExecLauncher):'
520 508 # SSH launchers
521 509 #-----------------------------------------------------------------------------
522 510
523 # TODO: Get SSH Launcher working again.
511 # TODO: Get SSH Launcher back to level of sshx in 0.10.2
524 512
525 513 class SSHLauncher(LocalProcessLauncher):
526 514 """A minimal launcher for ssh.
@@ -700,7 +688,7 b' class WindowsHPCLauncher(BaseLauncher):'
700 688 '/scheduler:%s' % self.scheduler
701 689 ]
702 690 self.log.info("Starting Win HPC Job: %s" % (self.job_cmd + ' ' + ' '.join(args),))
703 # Twisted will raise DeprecationWarnings if we try to pass unicode to this
691
704 692 output = check_output([self.job_cmd]+args,
705 693 env=os.environ,
706 694 cwd=self.work_dir,
@@ -1072,3 +1060,4 b' sge_launchers = ['
1072 1060 ]
1073 1061 all_launchers = local_launchers + mpi_launchers + ssh_launchers + winhpc_launchers\
1074 1062 + pbs_launchers + sge_launchers
1063
General Comments 0
You need to be logged in to leave comments. Login now