OLD | NEW |
1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
3 # found in the LICENSE file. | 3 # that can be 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 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 """Runs an executable; kill it in case of timeout.""" | 594 """Runs an executable; kill it in case of timeout.""" |
595 proc = Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, **kwargs) | 595 proc = Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, **kwargs) |
596 try: | 596 try: |
597 out, err = proc.communicate(timeout=timeout) | 597 out, err = proc.communicate(timeout=timeout) |
598 except TimeoutExpired as e: | 598 except TimeoutExpired as e: |
599 out = e.output | 599 out = e.output |
600 err = e.stderr | 600 err = e.stderr |
601 proc.kill() | 601 proc.kill() |
602 proc.wait() | 602 proc.wait() |
603 return out, err, proc.returncode, proc.duration() | 603 return out, err, proc.returncode, proc.duration() |
OLD | NEW |