Mercurial > hg > truffle
comparison mxtool/mx.py @ 4293:d4906ea4255b
Handle SIGTERM : killing mx will properly kill subprocesses
Some tabs/spaces mixups
author | Gilles Duboscq <gilles.m.duboscq@gmail.com> |
---|---|
date | Wed, 18 Jan 2012 16:53:04 +0100 |
parents | 311d193de5a2 |
children | 8dd27e218e19 |
comparison
equal
deleted
inserted
replaced
4292:48cbd78fa964 | 4293:d4906ea4255b |
---|---|
574 log(' '.join(args)) | 574 log(' '.join(args)) |
575 | 575 |
576 if timeout is None and _opts.ptimeout != 0: | 576 if timeout is None and _opts.ptimeout != 0: |
577 timeout = _opts.ptimeout | 577 timeout = _opts.ptimeout |
578 | 578 |
579 global _currentSubprocess | 579 global _currentSubprocess |
580 | 580 |
581 try: | 581 try: |
582 # On Unix, the new subprocess should be in a separate group so that a timeout alarm | 582 # On Unix, the new subprocess should be in a separate group so that a timeout alarm |
583 # can use os.killpg() to kill the whole subprocess group | 583 # can use os.killpg() to kill the whole subprocess group |
584 preexec_fn = None | 584 preexec_fn = None |
1616 | 1616 |
1617 if not commands.has_key(command): | 1617 if not commands.has_key(command): |
1618 abort('mx: unknown command \'{0}\'\n{1}use "mx help" for more options'.format(command, _format_commands())) | 1618 abort('mx: unknown command \'{0}\'\n{1}use "mx help" for more options'.format(command, _format_commands())) |
1619 | 1619 |
1620 c, _ = commands[command][:2] | 1620 c, _ = commands[command][:2] |
1621 def term_handler(signum, frame): | |
1622 abort(1) | |
1623 signal.signal(signal.SIGTERM, term_handler) | |
1621 try: | 1624 try: |
1622 if opts.timeout != 0: | 1625 if opts.timeout != 0: |
1623 def alarm_handler(signum, frame): | 1626 def alarm_handler(signum, frame): |
1624 abort('Command timed out after ' + str(opts.timeout) + ' seconds: ' + ' '.join(commandAndArgs)) | 1627 abort('Command timed out after ' + str(opts.timeout) + ' seconds: ' + ' '.join(commandAndArgs)) |
1625 signal.signal(signal.SIGALRM, alarm_handler) | 1628 signal.signal(signal.SIGALRM, alarm_handler) |