未验证 提交 c2079443 编写于 作者: K Kim 提交者: GitHub

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

* fix PLR1722

* fix issue

* fix error
上级 df423557
......@@ -16,6 +16,7 @@ import argparse
import json
import os
import pickle
import sys
import time
import traceback
......@@ -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
......
......@@ -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)
......
......@@ -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():
......@@ -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")
......
......@@ -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():
......@@ -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")
......
......@@ -24,7 +24,7 @@ from paddle.utils.cpp_extension import load
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"]
......
......@@ -318,5 +318,5 @@ class TestCppExtensionSetupInstall(unittest.TestCase):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
......@@ -326,5 +326,5 @@ class TestCustomCPUPlugin(unittest.TestCase):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
......@@ -71,5 +71,5 @@ class TestCustomCPUProfilerPlugin(unittest.TestCase):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
......@@ -279,5 +279,5 @@ class TestCustomCPUPlugin(unittest.TestCase):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
......@@ -284,5 +284,5 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase):
if __name__ == "__main__":
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
......@@ -13,6 +13,7 @@
# limitations under the License.
import os
import sys
import tempfile
import time
import unittest
......@@ -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())
......
......@@ -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,
......
......@@ -91,5 +91,5 @@ class TestCustomKernelDotC(unittest.TestCase):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
......@@ -88,5 +88,5 @@ class TestCustomKernelLoad(unittest.TestCase):
if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now
exit()
sys.exit()
unittest.main()
......@@ -346,5 +346,5 @@ if __name__ == '__main__':
# 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()
......@@ -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
......@@ -80,6 +82,6 @@ for data in train_reader():
(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)
......@@ -31,7 +31,7 @@ Diff: set(['test_parallel_executor_crf'])
"""
if len(sys.argv) < 2:
print(usage)
exit(0)
sys.exit(0)
logfile = sys.argv[1]
started = set()
......
......@@ -16,6 +16,7 @@ import argparse
import json
import logging
import os
import sys
def check_path_exists(path):
......@@ -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)
......@@ -217,4 +218,4 @@ if __name__ == "__main__":
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))
......@@ -16,6 +16,7 @@
import os
import os.path
import sys
from github import Github
......@@ -36,11 +37,11 @@ class PRChecker:
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
......
......@@ -107,7 +107,7 @@ while True:
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]
......@@ -129,7 +129,7 @@ while True:
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:
......
......@@ -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]
......
......@@ -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])
......
......@@ -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)
......@@ -73,7 +73,7 @@ if __name__ == '__main__':
)
)
exit(1)
sys.exit(1)
print(
'expected >= {} %, actual {} %, passed'.format(
......
......@@ -15,6 +15,7 @@
import argparse
import os
import re
import sys
# port range (21200, 23000) is reserved for dist-ops
......@@ -556,7 +557,7 @@ class CMakeGenerator:
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"
......
......@@ -19,6 +19,7 @@ import platform
import re
import ssl
import subprocess
import sys
import time
import urllib.request
......@@ -52,7 +53,7 @@ class PRChecker:
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
......@@ -311,7 +312,7 @@ class PRChecker:
)
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)
......@@ -371,7 +372,7 @@ class PRChecker:
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'
)
......@@ -484,7 +485,7 @@ class PRChecker:
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(
......
......@@ -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)
......@@ -724,7 +724,7 @@ if __name__ == '__main__':
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()
......@@ -760,7 +760,7 @@ if __name__ == '__main__':
"In addition, mistakes found in sample codes: %s", temp[1]
)
logger.info("----------------------------------------------------")
exit(1)
sys.exit(1)
else:
timeovered_test = {}
for temp in result:
......@@ -810,7 +810,7 @@ if __name__ == '__main__':
logger.info(
"Mistakes found in sample codes. Please recheck the sample codes."
)
exit(1)
sys.exit(1)
logger.info("Sample code check is successful!")
......
......@@ -63,7 +63,7 @@ def main():
paddle.disable_static()
if some_test_failed:
exit(1)
sys.exit(1)
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册