Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeStyle][PLR1722] replace exit() with sys.exit() #52151

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/paddle/distributed/auto_parallel/tuner/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import os
import pickle
import sys
import time
import traceback

Expand Down Expand Up @@ -291,7 +292,7 @@ def profiler(args):

data_loader._inner_dataloader.reset()
del data_loader._inner_dataloader
exit(1)
sys.exit(1)

data_loader._inner_dataloader.reset()
del data_loader._inner_dataloader
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/distributed/fleet/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def launch_collective(args):
except:
logger.warning("Terminating... exit")
terminate_local_procs(procs)
exit(1)
sys.exit(1)

if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/distributed/fleet/launch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def terminate_local_procs(procs):
time.sleep(3)

logger.fatal("can't kill all process and exit")
exit(1)
sys.exit(1)


def get_host_name_ip():
Expand Down Expand Up @@ -678,7 +678,7 @@ def watch_local_trainers(procs, nranks):

if error:
terminate_local_procs(procs)
exit(1)
sys.exit(1)

except KeyboardInterrupt:
logger.warning("KeyboardInterrupt, exit")
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/distributed/utils/launch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def terminate_local_procs(procs):
time.sleep(3)

logger.fatal("can't kill all process and exit")
exit(1)
sys.exit(1)


def get_host_name_ip():
Expand Down Expand Up @@ -543,7 +543,7 @@ def watch_local_trainers(procs, nranks):

if error:
terminate_local_procs(procs)
exit(1)
sys.exit(1)

except KeyboardInterrupt:
logger.warning("KeyboardInterrupt, exit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()

# Compile and load cpp extension Just-In-Time.
sources = ["custom_extension.cc", "custom_sub.cc"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,5 @@ def _test_double_grad_dynamic(self):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,5 @@ def _test_custom_device_py_api(self):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ def test_custom_profiler(self):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,5 @@ def forward(self, x):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,5 @@ def _test_stream(self):
if __name__ == "__main__":
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import sys
import tempfile
import time
import unittest
Expand Down Expand Up @@ -508,7 +509,7 @@ def train_mobilenet(args, to_static):
print(
"wrong model name, please try model = MobileNetV1 or MobileNetV2"
)
exit()
sys.exit()

optimizer = create_optimizer(args=args, parameter_list=net.parameters())

Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/multi_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def train_abort(prefix):
if trainer_id == 0:
try:
# train abort
exit(1)
sys.exit(1)
except SystemExit:
name = "abort>>> selected_gpus:{} worker_endpoints:{} trainers_num:{} current_endpoint:{} trainer_id:{}".format(
selected_gpus,
Expand Down
2 changes: 1 addition & 1 deletion test/custom_kernel/test_custom_kernel_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ def test_custom_kernel_dot_run(self):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
2 changes: 1 addition & 1 deletion test/custom_kernel/test_custom_kernel_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ def tearDown(self):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
2 changes: 1 addition & 1 deletion test/custom_op/test_custom_relu_op_xpu_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,5 @@ def test_with_dataloader(self):
# compile, install the custom op egg into site-packages under background
# Currently custom XPU op does not support Windows
if os.name == 'nt':
exit()
sys.exit()
unittest.main()
6 changes: 4 additions & 2 deletions test/legacy_test/test_error_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import paddle
from paddle import fluid

Expand Down Expand Up @@ -80,6 +82,6 @@
(out1.clip(min=CLIP_MIN, max=CLIP_MAX) == out1_clip).all()
and (out2 == out2_clip).all()
):
exit(1)
sys.exit(1)

exit(0)
sys.exit(0)
2 changes: 1 addition & 1 deletion tools/check_ctest_hung.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():
"""
if len(sys.argv) < 2:
print(usage)
exit(0)
sys.exit(0)

logfile = sys.argv[1]
started = set()
Expand Down
5 changes: 3 additions & 2 deletions tools/check_op_benchmark_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import logging
import os
import sys


def check_path_exists(path):
Expand Down Expand Up @@ -153,7 +154,7 @@ def update_api_info_file(fail_case_list, api_info_file):


def summary_results(check_results, api_info_file):
"""Summary results and return exit code."""
"""Summary results and return sys.exit code."""
for case_name in check_results["speed"]:
logging.error("Check speed result with case \"%s\" failed." % case_name)

Expand Down Expand Up @@ -217,4 +218,4 @@ def summary_results(check_results, api_info_file):
case_name, develop_result, pr_result, check_results
)

exit(summary_results(check_results, args.api_info_file))
sys.exit(summary_results(check_results, args.api_info_file))
5 changes: 3 additions & 2 deletions tools/check_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import os
import os.path
import sys

from github import Github

Expand All @@ -36,11 +37,11 @@ def check(self, filename, msg):
pr_id = os.getenv('GIT_PR_ID')
if not pr_id:
print('No PR ID')
exit(0)
sys.exit(0)
print(pr_id)
if not os.path.isfile(filename):
print('No author to check')
exit(0)
sys.exit(0)
self.repo = self.github.get_repo('PaddlePaddle/Paddle')
pr = self.repo.get_pull(int(pr_id))
user = pr.user.login
Expand Down
4 changes: 2 additions & 2 deletions tools/continuous_integration/bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def print_arguments():

if not commits:
sys.stdout.write('no commits to bisect\n')
exit()
sys.exit()
# checkout the picked branch.
pick_idx = len(commits) / 2
pick = commits[pick_idx]
Expand All @@ -129,7 +129,7 @@ def print_arguments():
subprocess.check_output([cmd], shell=True)
except subprocess.CalledProcessError as e:
sys.stderr.write('failed to build commit: %s\n%s\n' % (pick, e))
exit()
sys.exit()
# test the selected branch.
passed = True
try:
Expand Down
2 changes: 1 addition & 1 deletion tools/coverage/coverage_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def get_info_file_lines(info_file, diff_file):

if __name__ == '__main__':
if len(sys.argv) < 3:
exit()
sys.exit()

info_file = sys.argv[1]
diff_file = sys.argv[2]
Expand Down
2 changes: 1 addition & 1 deletion tools/coverage/coverage_diff_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def filter_by(list_file, max_rate):

if __name__ == '__main__':
if len(sys.argv) < 2:
exit()
sys.exit()

list_file = sys.argv[1]
max_rate = float(sys.argv[2])
Expand Down
8 changes: 4 additions & 4 deletions tools/coverage/coverage_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ def get_lines(info_file):

if total == 0:
print('no data found')
exit()
sys.exit()

return hits / total


if __name__ == '__main__':
if len(sys.argv) < 3:
exit()
sys.exit()

info_file = sys.argv[1]
expected = float(sys.argv[2])

if not os.path.isfile(info_file):
print('info file {} is not exists, ignored'.format(info_file))
exit()
sys.exit()

actual = get_lines(info_file)
actual = round(actual, 3)
Expand All @@ -73,7 +73,7 @@ def get_lines(info_file):
)
)

exit(1)
sys.exit(1)

print(
'expected >= {} %, actual {} %, passed'.format(
Expand Down
3 changes: 2 additions & 1 deletion tools/gen_ut_cmakelists.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import argparse
import os
import re
import sys

# port range (21200, 23000) is reserved for dist-ops

Expand Down Expand Up @@ -556,7 +557,7 @@ def _gen_cmakelists(self, current_work_dir, depth=0):
print(e)
print(f"[ERROR FILE]: {current_work_dir}/testslist.csv")
print(f"[ERROR LINE {i+1}]: {line.strip()}")
exit(1)
sys.exit(1)

for sub in sub_dirs:
cmds += f"add_subdirectory({sub})\n"
Expand Down
9 changes: 5 additions & 4 deletions tools/get_pr_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import re
import ssl
import subprocess
import sys
import time
import urllib.request

Expand Down Expand Up @@ -52,7 +53,7 @@ def init(self):
pr_id = os.getenv('GIT_PR_ID')
if not pr_id:
print('PREC No PR ID')
exit(0)
sys.exit(0)
suffix = os.getenv('PREC_SUFFIX')
if suffix:
self.suffix = suffix
Expand Down Expand Up @@ -311,7 +312,7 @@ def get_pr_ut(self):
)
if not ret:
print('PREC download file_ut.json failed')
exit(1)
sys.exit(1)

with open('ut_file_map.json') as jsonfile:
file_ut_map = json.load(jsonfile)
Expand Down Expand Up @@ -371,7 +372,7 @@ def get_pr_ut(self):
ut_list.append(ut.rstrip('\r\n'))
else:
print('PREC download prec_delta failed')
exit(1)
sys.exit(1)
PRECISION_TEST_Cases_ratio = format(
float(len(ut_list)) / float(self.get_all_count()), '.2f'
)
Expand Down Expand Up @@ -484,7 +485,7 @@ def get_pr_ut(self):
ut_list.append(ut.rstrip('\r\n'))
else:
print('PREC download prec_delta failed')
exit(1)
sys.exit(1)
print("hitMapFiles: %s" % hitMapFiles)
print("ipipe_log_param_PRECISION_TEST: true")
print(
Expand Down
8 changes: 4 additions & 4 deletions tools/sampcd_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def execute_samplecode(tfname):
else:
logger.error("Error: fail to parse python version!")
result = False
exit(1)
sys.exit(1)

logger.info("----example code check----")
logger.info("executing sample code: %s", tfname)
Expand Down Expand Up @@ -724,7 +724,7 @@ def parse_args():
filenames = get_filenames(args.full_test)
if len(filenames) == 0 and len(whl_error) == 0:
logger.info("-----API_PR.spec is the same as API_DEV.spec-----")
exit(0)
sys.exit(0)
logger.info("API_PR is diff from API_DEV: %s", filenames)

threads = multiprocessing.cpu_count()
Expand Down Expand Up @@ -760,7 +760,7 @@ def parse_args():
"In addition, mistakes found in sample codes: %s", temp[1]
)
logger.info("----------------------------------------------------")
exit(1)
sys.exit(1)
else:
timeovered_test = {}
for temp in result:
Expand Down Expand Up @@ -810,7 +810,7 @@ def parse_args():
logger.info(
"Mistakes found in sample codes. Please recheck the sample codes."
)
exit(1)
sys.exit(1)

logger.info("Sample code check is successful!")

Expand Down
Loading