Mercurial > hg > truffle
comparison mxtool/mx.py @ 4660:b06ade6e927c
Fixed Ctrl+C for Windows in mx.py
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 21 Feb 2012 19:30:33 +0100 |
parents | 7903b6c28f9c |
children | 60a8f52c0be0 |
comparison
equal
deleted
inserted
replaced
4659:bb90e461a139 | 4660:b06ade6e927c |
---|---|
555 | 555 |
556 # Makes the current subprocess accessible to the abort() function | 556 # Makes the current subprocess accessible to the abort() function |
557 # This is a tuple of the Popen object and args. | 557 # This is a tuple of the Popen object and args. |
558 _currentSubprocess = None | 558 _currentSubprocess = None |
559 | 559 |
560 def waitOn(p): | |
561 if get_os() == 'windows': | |
562 # on windows use a poll loop, otherwise signal does not get handled | |
563 retcode = None | |
564 while retcode == None: | |
565 retcode = p.poll() | |
566 time.sleep(0.05) | |
567 else: | |
568 retcode = p.wait() | |
569 return retcode | |
570 | |
560 def run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None): | 571 def run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None): |
561 """ | 572 """ |
562 Run a command in a subprocess, wait for it to complete and return the exit status of the process. | 573 Run a command in a subprocess, wait for it to complete and return the exit status of the process. |
563 If the exit status is non-zero and `nonZeroIsFatal` is true, then mx is exited with | 574 If the exit status is non-zero and `nonZeroIsFatal` is true, then mx is exited with |
564 the same exit status. | 575 the same exit status. |
590 | 601 |
591 if not callable(out) and not callable(err) and timeout is None: | 602 if not callable(out) and not callable(err) and timeout is None: |
592 # The preexec_fn=os.setsid | 603 # The preexec_fn=os.setsid |
593 p = subprocess.Popen(args, cwd=cwd, preexec_fn=preexec_fn, creationflags=creationflags) | 604 p = subprocess.Popen(args, cwd=cwd, preexec_fn=preexec_fn, creationflags=creationflags) |
594 _currentSubprocess = (p, args) | 605 _currentSubprocess = (p, args) |
595 if get_os() == 'windows': | 606 waitOn(p) |
596 # on windows use a poll loop, otherwise signal does not get handled | |
597 retcode = None | |
598 while retcode == None: | |
599 retcode = p.poll() | |
600 time.sleep(0.05) | |
601 else: | |
602 retcode = p.wait() | |
603 else: | 607 else: |
604 def redirect(stream, f): | 608 def redirect(stream, f): |
605 for line in iter(stream.readline, ''): | 609 for line in iter(stream.readline, ''): |
606 f(line) | 610 f(line) |
607 stream.close() | 611 stream.close() |
616 if callable(err): | 620 if callable(err): |
617 t = Thread(target=redirect, args=(p.stderr, err)) | 621 t = Thread(target=redirect, args=(p.stderr, err)) |
618 t.daemon = True # thread dies with the program | 622 t.daemon = True # thread dies with the program |
619 t.start() | 623 t.start() |
620 if timeout is None or timeout == 0: | 624 if timeout is None or timeout == 0: |
621 retcode = p.wait() | 625 retcode = waitOn(p) |
622 else: | 626 else: |
623 if get_os() == 'windows': | 627 if get_os() == 'windows': |
624 abort('Use of timeout not (yet) supported on Windows') | 628 abort('Use of timeout not (yet) supported on Windows') |
625 retcode = _waitWithTimeout(p, args, timeout) | 629 retcode = _waitWithTimeout(p, args, timeout) |
626 except OSError as e: | 630 except OSError as e: |