xref: /aosp_15_r20/external/pytorch/test/distributed/elastic/multiprocessing/bin/echo1.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1#!/usr/bin/env python3
2
3# Copyright (c) Facebook, Inc. and its affiliates.
4# All rights reserved.
5#
6# This source code is licensed under the BSD-style license found in the
7# LICENSE file in the root directory of this source tree.
8
9import argparse
10import os
11import sys
12
13
14if __name__ == "__main__":
15    parser = argparse.ArgumentParser(description="test binary, exits with exitcode")
16    parser.add_argument("--exitcode", type=int, default=0)
17    parser.add_argument("msg", type=str)
18    args = parser.parse_args()
19
20    rank = int(os.environ["RANK"])
21    exitcode = args.exitcode
22    if exitcode != 0:
23        print(f"exit {exitcode} from {rank}", file=sys.stderr)
24        sys.exit(exitcode)
25    else:
26        print(f"{args.msg} stdout from {rank}")
27        print(f"{args.msg} stderr from {rank}", file=sys.stderr)
28