Show More
@@ -0,0 +1,26 | |||||
|
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 from zmq.eventloop import ioloop | |||||
34 | from IPython.config.application import Application, boolean_flag |
|
34 | from IPython.config.application import Application, boolean_flag | |
35 | from IPython.config.loader import Config |
|
35 | from IPython.config.loader import Config | |
36 | from IPython.core.newapplication import BaseIPythonApplication, ProfileDir |
|
36 | from IPython.core.newapplication import BaseIPythonApplication, ProfileDir | |
|
37 | from IPython.utils.daemonize import daemonize | |||
37 | from IPython.utils.importstring import import_item |
|
38 | from IPython.utils.importstring import import_item | |
38 | from IPython.utils.traitlets import Int, Unicode, Bool, CFloat, Dict, List |
|
39 | from IPython.utils.traitlets import Int, Unicode, Bool, CFloat, Dict, List | |
39 |
|
40 | |||
@@ -368,7 +369,6 class IPClusterEngines(BaseParallelApplication): | |||||
368 | # TODO: Get daemonize working on Windows or as a Windows Server. |
|
369 | # TODO: Get daemonize working on Windows or as a Windows Server. | |
369 | if self.daemonize: |
|
370 | if self.daemonize: | |
370 | if os.name=='posix': |
|
371 | if os.name=='posix': | |
371 | from twisted.scripts._twistd_unix import daemonize |
|
|||
372 | daemonize() |
|
372 | daemonize() | |
373 |
|
373 | |||
374 | dc = ioloop.DelayedCallback(self.start_engines, 0, self.loop) |
|
374 | dc = ioloop.DelayedCallback(self.start_engines, 0, self.loop) | |
@@ -468,7 +468,6 class IPClusterStart(IPClusterEngines): | |||||
468 | # TODO: Get daemonize working on Windows or as a Windows Server. |
|
468 | # TODO: Get daemonize working on Windows or as a Windows Server. | |
469 | if self.daemonize: |
|
469 | if self.daemonize: | |
470 | if os.name=='posix': |
|
470 | if os.name=='posix': | |
471 | from twisted.scripts._twistd_unix import daemonize |
|
|||
472 | daemonize() |
|
471 | daemonize() | |
473 |
|
472 | |||
474 | dc = ioloop.DelayedCallback(self.start_controller, 0, self.loop) |
|
473 | dc = ioloop.DelayedCallback(self.start_controller, 0, self.loop) |
@@ -157,29 +157,20 class BaseLauncher(LoggingConfigurable): | |||||
157 | return False |
|
157 | return False | |
158 |
|
158 | |||
159 | def start(self): |
|
159 | def start(self): | |
160 | """Start the process. |
|
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 | """ |
|
|||
165 | raise NotImplementedError('start must be implemented in a subclass') |
|
161 | raise NotImplementedError('start must be implemented in a subclass') | |
166 |
|
162 | |||
167 | def stop(self): |
|
163 | def stop(self): | |
168 | """Stop the process and notify observers of stopping. |
|
164 | """Stop the process and notify observers of stopping. | |
169 |
|
165 | |||
170 | This must return a deferred that fires with information about the |
|
166 | This method will return None immediately. | |
171 | processing stopping, like errors that occur while the process is |
|
167 | To observe the actual process stopping, see :meth:`on_stop`. | |
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`. |
|
|||
175 | """ |
|
168 | """ | |
176 | raise NotImplementedError('stop must be implemented in a subclass') |
|
169 | raise NotImplementedError('stop must be implemented in a subclass') | |
177 |
|
170 | |||
178 | def on_stop(self, f): |
|
171 | def on_stop(self, f): | |
179 | """Get a deferred that will fire when the process stops. |
|
172 | """Register a callback to be called with this Launcher's stop_data | |
180 |
|
173 | when the process actually finishes. | ||
181 | The deferred will fire with data that contains information about |
|
|||
182 | the exit status of the process. |
|
|||
183 | """ |
|
174 | """ | |
184 | if self.state=='after': |
|
175 | if self.state=='after': | |
185 | return f(self.stop_data) |
|
176 | return f(self.stop_data) | |
@@ -202,7 +193,7 class BaseLauncher(LoggingConfigurable): | |||||
202 | """Call this to trigger process stop actions. |
|
193 | """Call this to trigger process stop actions. | |
203 |
|
194 | |||
204 | This logs the process stopping and sets the state to 'after'. Call |
|
195 | This logs the process stopping and sets the state to 'after'. Call | |
205 |
this to trigger |
|
196 | this to trigger callbacks registered via :meth:`on_stop`.""" | |
206 |
|
197 | |||
207 | self.log.info('Process %r stopped: %r' % (self.args[0], data)) |
|
198 | self.log.info('Process %r stopped: %r' % (self.args[0], data)) | |
208 | self.stop_data = data |
|
199 | self.stop_data = data | |
@@ -215,8 +206,6 class BaseLauncher(LoggingConfigurable): | |||||
215 | def signal(self, sig): |
|
206 | def signal(self, sig): | |
216 | """Signal the process. |
|
207 | """Signal the process. | |
217 |
|
208 | |||
218 | Return a semi-meaningless deferred after signaling the process. |
|
|||
219 |
|
||||
220 | Parameters |
|
209 | Parameters | |
221 | ---------- |
|
210 | ---------- | |
222 | sig : str or int |
|
211 | sig : str or int | |
@@ -247,7 +236,6 class LocalProcessLauncher(BaseLauncher): | |||||
247 | work_dir=work_dir, config=config, **kwargs |
|
236 | work_dir=work_dir, config=config, **kwargs | |
248 | ) |
|
237 | ) | |
249 | self.process = None |
|
238 | self.process = None | |
250 | self.start_deferred = None |
|
|||
251 | self.poller = None |
|
239 | self.poller = None | |
252 |
|
240 | |||
253 | def find_args(self): |
|
241 | def find_args(self): | |
@@ -520,7 +508,7 class MPIExecEngineSetLauncher(MPIExecLauncher): | |||||
520 | # SSH launchers |
|
508 | # SSH launchers | |
521 | #----------------------------------------------------------------------------- |
|
509 | #----------------------------------------------------------------------------- | |
522 |
|
510 | |||
523 |
# TODO: Get SSH Launcher |
|
511 | # TODO: Get SSH Launcher back to level of sshx in 0.10.2 | |
524 |
|
512 | |||
525 | class SSHLauncher(LocalProcessLauncher): |
|
513 | class SSHLauncher(LocalProcessLauncher): | |
526 | """A minimal launcher for ssh. |
|
514 | """A minimal launcher for ssh. | |
@@ -700,7 +688,7 class WindowsHPCLauncher(BaseLauncher): | |||||
700 | '/scheduler:%s' % self.scheduler |
|
688 | '/scheduler:%s' % self.scheduler | |
701 | ] |
|
689 | ] | |
702 | self.log.info("Starting Win HPC Job: %s" % (self.job_cmd + ' ' + ' '.join(args),)) |
|
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 | output = check_output([self.job_cmd]+args, |
|
692 | output = check_output([self.job_cmd]+args, | |
705 | env=os.environ, |
|
693 | env=os.environ, | |
706 | cwd=self.work_dir, |
|
694 | cwd=self.work_dir, | |
@@ -1072,3 +1060,4 sge_launchers = [ | |||||
1072 | ] |
|
1060 | ] | |
1073 | all_launchers = local_launchers + mpi_launchers + ssh_launchers + winhpc_launchers\ |
|
1061 | all_launchers = local_launchers + mpi_launchers + ssh_launchers + winhpc_launchers\ | |
1074 | + pbs_launchers + sge_launchers |
|
1062 | + pbs_launchers + sge_launchers | |
|
1063 |
General Comments 0
You need to be logged in to leave comments.
Login now