comparison mxtool/mx.py @ 4239:676feaf8adee

Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter).
author Doug Simon <doug.simon@oracle.com>
date Fri, 06 Jan 2012 17:45:40 +0100
parents 11383dafc318
children 8fece0287975
comparison
equal deleted inserted replaced
4238:e0d09e05aa9b 4239:676feaf8adee
85 # 85 #
86 # Other properties can be specified for projects and libraries for use by extension commands. 86 # Other properties can be specified for projects and libraries for use by extension commands.
87 # 87 #
88 # Values can use environment variables with Bash syntax (e.g. ${HOME}). 88 # Values can use environment variables with Bash syntax (e.g. ${HOME}).
89 89
90 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile 90 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal
91 import shutil, fnmatch, re, xml.dom.minidom 91 import shutil, fnmatch, re, xml.dom.minidom
92 from collections import Callable 92 from collections import Callable
93 from threading import Thread 93 from threading import Thread
94 from argparse import ArgumentParser, REMAINDER 94 from argparse import ArgumentParser, REMAINDER
95 from os.path import join, dirname, exists, getmtime, isabs, expandvars, isdir 95 from os.path import join, dirname, exists, getmtime, isabs, expandvars, isdir
460 self.add_argument('--J', dest='java_args', help='Java VM arguments (e.g. --J @-dsa)', metavar='@<args>', default=DEFAULT_JAVA_ARGS) 460 self.add_argument('--J', dest='java_args', help='Java VM arguments (e.g. --J @-dsa)', metavar='@<args>', default=DEFAULT_JAVA_ARGS)
461 self.add_argument('--Jp', action='append', dest='java_args_pfx', help='prefix Java VM arguments (e.g. --Jp @-dsa)', metavar='@<args>', default=[]) 461 self.add_argument('--Jp', action='append', dest='java_args_pfx', help='prefix Java VM arguments (e.g. --Jp @-dsa)', metavar='@<args>', default=[])
462 self.add_argument('--Ja', action='append', dest='java_args_sfx', help='suffix Java VM arguments (e.g. --Ja @-dsa)', metavar='@<args>', default=[]) 462 self.add_argument('--Ja', action='append', dest='java_args_sfx', help='suffix Java VM arguments (e.g. --Ja @-dsa)', metavar='@<args>', default=[])
463 self.add_argument('--user-home', help='users home directory', metavar='<path>', default=os.path.expanduser('~')) 463 self.add_argument('--user-home', help='users home directory', metavar='<path>', default=os.path.expanduser('~'))
464 self.add_argument('--java-home', help='JDK installation directory (must be JDK 6 or later)', metavar='<path>') 464 self.add_argument('--java-home', help='JDK installation directory (must be JDK 6 or later)', metavar='<path>')
465 self.add_argument('--timeout', help='Timeout (in seconds) for subprocesses', type=int, default=0, metavar='<secs>') 465 if get_os() != 'windows':
466 # Time outs are (currently) implemented with Unix specific functionality
467 self.add_argument('--timeout', help='Timeout (in seconds) for command', type=int, default=0, metavar='<secs>')
468 self.add_argument('--ptimeout', help='Timeout (in seconds) for subprocesses', type=int, default=0, metavar='<secs>')
469
466 470
467 def _parse_cmd_line(self, args=None): 471 def _parse_cmd_line(self, args=None):
468 if args is None: 472 if args is None:
469 args = sys.argv[1:] 473 args = sys.argv[1:]
470 474
1212 if not commands.has_key(command): 1216 if not commands.has_key(command):
1213 abort('mx: unknown command \'{0}\'\n{1}use "mx help" for more options'.format(command, _format_commands())) 1217 abort('mx: unknown command \'{0}\'\n{1}use "mx help" for more options'.format(command, _format_commands()))
1214 1218
1215 c, _ = commands[command][:2] 1219 c, _ = commands[command][:2]
1216 try: 1220 try:
1221 if opts.timeout != 0:
1222 def alarm_handler(signum, frame):
1223 abort('Command timed out after ' + str(opts.timeout) + ' seconds: ' + ' '.join(commandAndArgs))
1224 signal.signal(signal.SIGALRM, alarm_handler)
1225 signal.alarm(opts.timeout)
1217 retcode = c(command_args) 1226 retcode = c(command_args)
1218 if retcode is not None and retcode != 0: 1227 if retcode is not None and retcode != 0:
1219 abort(retcode) 1228 abort(retcode)
1220 except KeyboardInterrupt: 1229 except KeyboardInterrupt:
1221 # no need to show the stack trace when the user presses CTRL-C 1230 # no need to show the stack trace when the user presses CTRL-C