# HG changeset patch # User Doug Simon # Date 1325868340 -3600 # Node ID 676feaf8adeed4cb3e7a102a60f42cca0bbef189 # Parent e0d09e05aa9bffb20f54e40d0e7f4f78a7ac0c74 Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter). diff -r e0d09e05aa9b -r 676feaf8adee mxtool/mx.py --- a/mxtool/mx.py Fri Jan 06 17:44:22 2012 +0100 +++ b/mxtool/mx.py Fri Jan 06 17:45:40 2012 +0100 @@ -87,7 +87,7 @@ # # Values can use environment variables with Bash syntax (e.g. ${HOME}). -import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile +import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal import shutil, fnmatch, re, xml.dom.minidom from collections import Callable from threading import Thread @@ -462,7 +462,11 @@ self.add_argument('--Ja', action='append', dest='java_args_sfx', help='suffix Java VM arguments (e.g. --Ja @-dsa)', metavar='@', default=[]) self.add_argument('--user-home', help='users home directory', metavar='', default=os.path.expanduser('~')) self.add_argument('--java-home', help='JDK installation directory (must be JDK 6 or later)', metavar='') - self.add_argument('--timeout', help='Timeout (in seconds) for subprocesses', type=int, default=0, metavar='') + if get_os() != 'windows': + # Time outs are (currently) implemented with Unix specific functionality + self.add_argument('--timeout', help='Timeout (in seconds) for command', type=int, default=0, metavar='') + self.add_argument('--ptimeout', help='Timeout (in seconds) for subprocesses', type=int, default=0, metavar='') + def _parse_cmd_line(self, args=None): if args is None: @@ -1214,6 +1218,11 @@ c, _ = commands[command][:2] try: + if opts.timeout != 0: + def alarm_handler(signum, frame): + abort('Command timed out after ' + str(opts.timeout) + ' seconds: ' + ' '.join(commandAndArgs)) + signal.signal(signal.SIGALRM, alarm_handler) + signal.alarm(opts.timeout) retcode = c(command_args) if retcode is not None and retcode != 0: abort(retcode)