##// END OF EJS Templates
The local mode of ipcluster now works on Win32.
Brian Granger -
Show More
@@ -14,8 +14,16 b' from IPython.external import argparse'
14 from IPython.external import Itpl
14 from IPython.external import Itpl
15 from IPython.kernel.twistedutil import gatherBoth
15 from IPython.kernel.twistedutil import gatherBoth
16 from IPython.kernel.util import printer
16 from IPython.kernel.util import printer
17 from IPython.genutils import get_ipython_dir
17 from IPython.genutils import get_ipython_dir, num_cpus
18
18
19 def find_exe(cmd):
20 try:
21 import win32api
22 except ImportError:
23 raise ImportError('you need to have pywin32 installed for this to work')
24 else:
25 (path, offest) = win32api.SearchPath(os.environ['PATH'],cmd)
26 return path
19
27
20 # Test local cluster on Win32
28 # Test local cluster on Win32
21 # Look at local cluster usage strings
29 # Look at local cluster usage strings
@@ -66,7 +74,6 b' class ProcessLauncher(object):'
66 a formal NotificationCenter.
74 a formal NotificationCenter.
67 """
75 """
68 def __init__(self, cmd_and_args):
76 def __init__(self, cmd_and_args):
69
70 self.cmd = cmd_and_args[0]
77 self.cmd = cmd_and_args[0]
71 self.args = cmd_and_args
78 self.args = cmd_and_args
72 self._reset()
79 self._reset()
@@ -131,8 +138,8 b' class ProcessLauncher(object):'
131 if self.state == 'running':
138 if self.state == 'running':
132 self.process_transport.signalProcess(sig)
139 self.process_transport.signalProcess(sig)
133
140
134 def __del__(self):
141 # def __del__(self):
135 self.signal('KILL')
142 # self.signal('KILL')
136
143
137 def interrupt_then_kill(self, delay=1.0):
144 def interrupt_then_kill(self, delay=1.0):
138 self.signal('INT')
145 self.signal('INT')
@@ -142,23 +149,29 b' class ProcessLauncher(object):'
142 class ControllerLauncher(ProcessLauncher):
149 class ControllerLauncher(ProcessLauncher):
143
150
144 def __init__(self, extra_args=None):
151 def __init__(self, extra_args=None):
145 self.args = ['ipcontroller']
152 if sys.platform == 'win32':
153 args = [find_exe('ipcontroller.bat')]
154 else:
155 args = ['ipcontroller']
146 self.extra_args = extra_args
156 self.extra_args = extra_args
147 if extra_args is not None:
157 if extra_args is not None:
148 self.args.extend(extra_args)
158 args.extend(extra_args)
149
159
150 ProcessLauncher.__init__(self, self.args)
160 ProcessLauncher.__init__(self, args)
151
161
152
162
153 class EngineLauncher(ProcessLauncher):
163 class EngineLauncher(ProcessLauncher):
154
164
155 def __init__(self, extra_args=None):
165 def __init__(self, extra_args=None):
156 self.args = ['ipengine']
166 if sys.platform == 'win32':
167 args = [find_exe('ipengine.bat')]
168 else:
169 args = ['ipengine']
157 self.extra_args = extra_args
170 self.extra_args = extra_args
158 if extra_args is not None:
171 if extra_args is not None:
159 self.args.extend(extra_args)
172 args.extend(extra_args)
160
173
161 ProcessLauncher.__init__(self, self.args)
174 ProcessLauncher.__init__(self, args)
162
175
163
176
164 class LocalEngineSet(object):
177 class LocalEngineSet(object):
@@ -271,6 +284,10 b' class PBSEngineSet(BatchEngineSet):'
271 def main_local(args):
284 def main_local(args):
272 cont_args = []
285 cont_args = []
273 cont_args.append('--logfile=%s' % pjoin(args.logdir,'ipcontroller'))
286 cont_args.append('--logfile=%s' % pjoin(args.logdir,'ipcontroller'))
287 if args.x:
288 cont_args.append('-x')
289 if args.y:
290 cont_args.append('-y')
274 cl = ControllerLauncher(extra_args=cont_args)
291 cl = ControllerLauncher(extra_args=cont_args)
275 dstart = cl.start()
292 dstart = cl.start()
276 def start_engines(cont_pid):
293 def start_engines(cont_pid):
@@ -299,6 +316,10 b' def main_local(args):'
299 def main_mpirun(args):
316 def main_mpirun(args):
300 cont_args = []
317 cont_args = []
301 cont_args.append('--logfile=%s' % pjoin(args.logdir,'ipcontroller'))
318 cont_args.append('--logfile=%s' % pjoin(args.logdir,'ipcontroller'))
319 if args.x:
320 cont_args.append('-x')
321 if args.y:
322 cont_args.append('-y')
302 cl = ControllerLauncher(extra_args=cont_args)
323 cl = ControllerLauncher(extra_args=cont_args)
303 dstart = cl.start()
324 dstart = cl.start()
304 def start_engines(cont_pid):
325 def start_engines(cont_pid):
@@ -340,29 +361,62 b' def main_pbs(args):'
340
361
341
362
342 def get_args():
363 def get_args():
343 parser = argparse.ArgumentParser(
364 base_parser = argparse.ArgumentParser(add_help=False)
344 description='IPython cluster startup')
365 base_parser.add_argument(
345 newopt = parser.add_argument # shorthand
366 '-x',
367 action='store_true',
368 dest='x',
369 help='turn off client security'
370 )
371 base_parser.add_argument(
372 '-y',
373 action='store_true',
374 dest='y',
375 help='turn off engine security'
376 )
377 base_parser.add_argument(
378 "--logdir",
379 type=str,
380 dest="logdir",
381 help="directory to put log files (default=$IPYTHONDIR/log)",
382 default=pjoin(get_ipython_dir(),'log')
383 )
384 base_parser.add_argument(
385 "-n",
386 "--num",
387 type=int,
388 dest="n",
389 default=2,
390 help="the number of engines to start"
391 )
346
392
347 subparsers = parser.add_subparsers(help='sub-command help')
393 parser = argparse.ArgumentParser(
394 description='IPython cluster startup. This starts a controller and\
395 engines using various approaches'
396 )
397 subparsers = parser.add_subparsers(
398 help='available cluster types. For help, do "ipcluster TYPE --help"')
348
399
349 parser_local = subparsers.add_parser('local', help='run a local cluster')
400 parser_local = subparsers.add_parser(
350 parser_local.add_argument("--logdir", type=str, dest="logdir",
401 'local',
351 help="directory to put log files (default=$IPYTHONDIR/log)",
402 help='run a local cluster',
352 default=pjoin(get_ipython_dir(),'log'))
403 parents=[base_parser]
353 parser_local.add_argument("-n", "--num", type=int, dest="n",default=2,
404 )
354 help="the number of engines to start")
355 parser_local.set_defaults(func=main_local)
405 parser_local.set_defaults(func=main_local)
356
406
357 parser_local = subparsers.add_parser('mpirun', help='run a cluster using mpirun')
407 parser_mpirun = subparsers.add_parser(
358 parser_local.add_argument("--logdir", type=str, dest="logdir",
408 'mpirun',
359 help="directory to put log files (default=$IPYTHONDIR/log)",
409 help='run a cluster using mpirun',
360 default=pjoin(get_ipython_dir(),'log'))
410 parents=[base_parser]
361 parser_local.add_argument("-n", "--num", type=int, dest="n",default=2,
411 )
362 help="the number of engines to start")
412 parser_mpirun.add_argument(
363 parser_local.add_argument("--mpi", type=str, dest="mpi",default='mpi4py',
413 "--mpi",
364 help="how to call MPI_Init (default=mpi4py)")
414 type=str,
365 parser_local.set_defaults(func=main_mpirun)
415 dest="mpi",
416 default='mpi4py',
417 help="how to call MPI_Init (default=mpi4py)"
418 )
419 parser_mpirun.set_defaults(func=main_mpirun)
366
420
367 parser_pbs = subparsers.add_parser('pbs', help='run a pbs cluster')
421 parser_pbs = subparsers.add_parser('pbs', help='run a pbs cluster')
368 parser_pbs.add_argument('--pbs-script', type=str, dest='pbsscript',
422 parser_pbs.add_argument('--pbs-script', type=str, dest='pbsscript',
General Comments 0
You need to be logged in to leave comments. Login now