Run a function with a timeout. If timeout is reached, exit program. target: target function to run. args: list of positional arguments passed to the target function. secs: timeout in seconds.
(target, args, secs)
| 229 | continue |
| 230 | |
| 231 | def _runwithtimeout(target, args, secs): |
| 232 | """ |
| 233 | Run a function with a timeout. If timeout is reached, exit program. |
| 234 | target: target function to run. |
| 235 | args: list of positional arguments passed to the target function. |
| 236 | secs: timeout in seconds. |
| 237 | """ |
| 238 | t = Thread(target=target, args=args, daemon=True) |
| 239 | t.start() |
| 240 | t.join(timeout=secs) |
| 241 | if t.is_alive(): |
| 242 | print(f'{target} timed out after {secs} secs') |
| 243 | sys.exit(1) |
| 244 | |
| 245 | def printsecrets(ns, to_stdout=True): |
| 246 | """ |