|
1 | 1 | from abc import ABCMeta, abstractmethod |
2 | | -from typing import List, Tuple |
| 2 | +from typing import Any, List, Tuple |
3 | 3 |
|
4 | 4 | from dargs import Argument |
5 | 5 |
|
@@ -73,6 +73,66 @@ def read_file(self, fname): |
73 | 73 | def check_finish(self, proc): |
74 | 74 | raise NotImplementedError("abstract method") |
75 | 75 |
|
| 76 | + def block_checkcall(self, cmd, asynchronously=False) -> Tuple[Any, Any, Any]: |
| 77 | + """Run command with arguments. Wait for command to complete. |
| 78 | +
|
| 79 | + Parameters |
| 80 | + ---------- |
| 81 | + cmd : str |
| 82 | + The command to run. |
| 83 | + asynchronously : bool, optional, default=False |
| 84 | + Run command asynchronously. If True, `nohup` will be used to run the command. |
| 85 | +
|
| 86 | + Returns |
| 87 | + ------- |
| 88 | + stdin |
| 89 | + standard inout |
| 90 | + stdout |
| 91 | + standard output |
| 92 | + stderr |
| 93 | + standard error |
| 94 | +
|
| 95 | + Raises |
| 96 | + ------ |
| 97 | + RuntimeError |
| 98 | + when the return code is not zero |
| 99 | + """ |
| 100 | + if asynchronously: |
| 101 | + cmd = f"nohup {cmd} >/dev/null &" |
| 102 | + exit_status, stdin, stdout, stderr = self.block_call(cmd) |
| 103 | + if exit_status != 0: |
| 104 | + raise RuntimeError( |
| 105 | + "Get error code %d in calling %s with job: %s . message: %s" |
| 106 | + % ( |
| 107 | + exit_status, |
| 108 | + cmd, |
| 109 | + self.submission.submission_hash, |
| 110 | + stderr.read().decode("utf-8"), |
| 111 | + ) |
| 112 | + ) |
| 113 | + return stdin, stdout, stderr |
| 114 | + |
| 115 | + @abstractmethod |
| 116 | + def block_call(self, cmd) -> Tuple[int, Any, Any, Any]: |
| 117 | + """Run command with arguments. Wait for command to complete. |
| 118 | +
|
| 119 | + Parameters |
| 120 | + ---------- |
| 121 | + cmd : str |
| 122 | + The command to run. |
| 123 | +
|
| 124 | + Returns |
| 125 | + ------- |
| 126 | + exit_status |
| 127 | + exit code |
| 128 | + stdin |
| 129 | + standard inout |
| 130 | + stdout |
| 131 | + standard output |
| 132 | + stderr |
| 133 | + standard error |
| 134 | + """ |
| 135 | + |
76 | 136 | @classmethod |
77 | 137 | def machine_arginfo(cls) -> Argument: |
78 | 138 | """Generate the machine arginfo. |
|
0 commit comments