OLD | NEW |
1 # Copyright 2013 The Swarming Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
2 # Use of this source code is governed under the Apache License, Version 2.0 that | 2 # Use of this source code is governed by the Apache v2.0 license that can be |
3 # can be found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """subprocess42 is the answer to life the universe and everything. | 5 """subprocess42 is the answer to life the universe and everything. |
6 | 6 |
7 It has the particularity of having a Popen implementation that can yield output | 7 It has the particularity of having a Popen implementation that can yield output |
8 as it is produced while implementing a timeout and NOT requiring the use of | 8 as it is produced while implementing a timeout and NOT requiring the use of |
9 worker threads. | 9 worker threads. |
10 | 10 |
11 Example: | 11 Example: |
12 Wait for a child process with a timeout, send SIGTERM, wait a grace period | 12 Wait for a child process with a timeout, send SIGTERM, wait a grace period |
13 then send SIGKILL: | 13 then send SIGKILL: |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 """Runs an executable; kill it in case of timeout.""" | 582 """Runs an executable; kill it in case of timeout.""" |
583 proc = Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, **kwargs) | 583 proc = Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, **kwargs) |
584 try: | 584 try: |
585 out, err = proc.communicate(timeout=timeout) | 585 out, err = proc.communicate(timeout=timeout) |
586 except TimeoutExpired as e: | 586 except TimeoutExpired as e: |
587 out = e.output | 587 out = e.output |
588 err = e.stderr | 588 err = e.stderr |
589 proc.kill() | 589 proc.kill() |
590 proc.wait() | 590 proc.wait() |
591 return out, err, proc.returncode, proc.duration() | 591 return out, err, proc.returncode, proc.duration() |
OLD | NEW |