未验证 提交 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 ...@@ -16,6 +16,7 @@ import argparse
import json import json
import os import os
import pickle import pickle
import sys
import time import time
import traceback import traceback
...@@ -291,7 +292,7 @@ def profiler(args): ...@@ -291,7 +292,7 @@ def profiler(args):
data_loader._inner_dataloader.reset() data_loader._inner_dataloader.reset()
del data_loader._inner_dataloader del data_loader._inner_dataloader
exit(1) sys.exit(1)
data_loader._inner_dataloader.reset() data_loader._inner_dataloader.reset()
del data_loader._inner_dataloader del data_loader._inner_dataloader
......
...@@ -476,7 +476,7 @@ def launch_collective(args): ...@@ -476,7 +476,7 @@ def launch_collective(args):
except: except:
logger.warning("Terminating... exit") logger.warning("Terminating... exit")
terminate_local_procs(procs) terminate_local_procs(procs)
exit(1) sys.exit(1)
if os.path.exists(tmp_dir): if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir) shutil.rmtree(tmp_dir)
......
...@@ -370,7 +370,7 @@ def terminate_local_procs(procs): ...@@ -370,7 +370,7 @@ def terminate_local_procs(procs):
time.sleep(3) time.sleep(3)
logger.fatal("can't kill all process and exit") logger.fatal("can't kill all process and exit")
exit(1) sys.exit(1)
def get_host_name_ip(): def get_host_name_ip():
...@@ -678,7 +678,7 @@ def watch_local_trainers(procs, nranks): ...@@ -678,7 +678,7 @@ def watch_local_trainers(procs, nranks):
if error: if error:
terminate_local_procs(procs) terminate_local_procs(procs)
exit(1) sys.exit(1)
except KeyboardInterrupt: except KeyboardInterrupt:
logger.warning("KeyboardInterrupt, exit") logger.warning("KeyboardInterrupt, exit")
......
...@@ -354,7 +354,7 @@ def terminate_local_procs(procs): ...@@ -354,7 +354,7 @@ def terminate_local_procs(procs):
time.sleep(3) time.sleep(3)
logger.fatal("can't kill all process and exit") logger.fatal("can't kill all process and exit")
exit(1) sys.exit(1)
def get_host_name_ip(): def get_host_name_ip():
...@@ -543,7 +543,7 @@ def watch_local_trainers(procs, nranks): ...@@ -543,7 +543,7 @@ def watch_local_trainers(procs, nranks):
if error: if error:
terminate_local_procs(procs) terminate_local_procs(procs)
exit(1) sys.exit(1)
except KeyboardInterrupt: except KeyboardInterrupt:
logger.warning("KeyboardInterrupt, exit") logger.warning("KeyboardInterrupt, exit")
......
...@@ -24,7 +24,7 @@ from paddle.utils.cpp_extension import load ...@@ -24,7 +24,7 @@ from paddle.utils.cpp_extension import load
if os.name == 'nt' or sys.platform.startswith('darwin'): if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now # only support Linux now
exit() sys.exit()
# Compile and load cpp extension Just-In-Time. # Compile and load cpp extension Just-In-Time.
sources = ["custom_extension.cc", "custom_sub.cc"] sources = ["custom_extension.cc", "custom_sub.cc"]
......
...@@ -318,5 +318,5 @@ class TestCppExtensionSetupInstall(unittest.TestCase): ...@@ -318,5 +318,5 @@ class TestCppExtensionSetupInstall(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'): if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now # only support Linux now
exit() sys.exit()
unittest.main() unittest.main()
...@@ -326,5 +326,5 @@ class TestCustomCPUPlugin(unittest.TestCase): ...@@ -326,5 +326,5 @@ class TestCustomCPUPlugin(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'): if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now # only support Linux now
exit() sys.exit()
unittest.main() unittest.main()
...@@ -71,5 +71,5 @@ class TestCustomCPUProfilerPlugin(unittest.TestCase): ...@@ -71,5 +71,5 @@ class TestCustomCPUProfilerPlugin(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'): if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now # only support Linux now
exit() sys.exit()
unittest.main() unittest.main()
...@@ -279,5 +279,5 @@ class TestCustomCPUPlugin(unittest.TestCase): ...@@ -279,5 +279,5 @@ class TestCustomCPUPlugin(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'): if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now # only support Linux now
exit() sys.exit()
unittest.main() unittest.main()
...@@ -284,5 +284,5 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase): ...@@ -284,5 +284,5 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase):
if __name__ == "__main__": if __name__ == "__main__":
if os.name == 'nt' or sys.platform.startswith('darwin'): if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now # only support Linux now
exit() sys.exit()
unittest.main() unittest.main()
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
import tempfile import tempfile
import time import time
import unittest import unittest
...@@ -508,7 +509,7 @@ def train_mobilenet(args, to_static): ...@@ -508,7 +509,7 @@ def train_mobilenet(args, to_static):
print( print(
"wrong model name, please try model = MobileNetV1 or MobileNetV2" "wrong model name, please try model = MobileNetV1 or MobileNetV2"
) )
exit() sys.exit()
optimizer = create_optimizer(args=args, parameter_list=net.parameters()) optimizer = create_optimizer(args=args, parameter_list=net.parameters())
......
...@@ -51,7 +51,7 @@ def train_abort(prefix): ...@@ -51,7 +51,7 @@ def train_abort(prefix):
if trainer_id == 0: if trainer_id == 0:
try: try:
# train abort # train abort
exit(1) sys.exit(1)
except SystemExit: except SystemExit:
name = "abort>>> selected_gpus:{} worker_endpoints:{} trainers_num:{} current_endpoint:{} trainer_id:{}".format( name = "abort>>> selected_gpus:{} worker_endpoints:{} trainers_num:{} current_endpoint:{} trainer_id:{}".format(
selected_gpus, selected_gpus,
......
...@@ -91,5 +91,5 @@ class TestCustomKernelDotC(unittest.TestCase): ...@@ -91,5 +91,5 @@ class TestCustomKernelDotC(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'): if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now # only support Linux now
exit() sys.exit()
unittest.main() unittest.main()
...@@ -88,5 +88,5 @@ class TestCustomKernelLoad(unittest.TestCase): ...@@ -88,5 +88,5 @@ class TestCustomKernelLoad(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
if os.name == 'nt' or sys.platform.startswith('darwin'): if os.name == 'nt' or sys.platform.startswith('darwin'):
# only support Linux now # only support Linux now
exit() sys.exit()
unittest.main() unittest.main()
...@@ -346,5 +346,5 @@ if __name__ == '__main__': ...@@ -346,5 +346,5 @@ if __name__ == '__main__':
# compile, install the custom op egg into site-packages under background # compile, install the custom op egg into site-packages under background
# Currently custom XPU op does not support Windows # Currently custom XPU op does not support Windows
if os.name == 'nt': if os.name == 'nt':
exit() sys.exit()
unittest.main() unittest.main()
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import sys
import paddle import paddle
from paddle import fluid from paddle import fluid
...@@ -80,6 +82,6 @@ for data in train_reader(): ...@@ -80,6 +82,6 @@ for data in train_reader():
(out1.clip(min=CLIP_MIN, max=CLIP_MAX) == out1_clip).all() (out1.clip(min=CLIP_MIN, max=CLIP_MAX) == out1_clip).all()
and (out2 == out2_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']) ...@@ -31,7 +31,7 @@ Diff: set(['test_parallel_executor_crf'])
""" """
if len(sys.argv) < 2: if len(sys.argv) < 2:
print(usage) print(usage)
exit(0) sys.exit(0)
logfile = sys.argv[1] logfile = sys.argv[1]
started = set() started = set()
......
...@@ -16,6 +16,7 @@ import argparse ...@@ -16,6 +16,7 @@ import argparse
import json import json
import logging import logging
import os import os
import sys
def check_path_exists(path): def check_path_exists(path):
...@@ -153,7 +154,7 @@ def update_api_info_file(fail_case_list, api_info_file): ...@@ -153,7 +154,7 @@ def update_api_info_file(fail_case_list, api_info_file):
def summary_results(check_results, 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"]: for case_name in check_results["speed"]:
logging.error("Check speed result with case \"%s\" failed." % case_name) logging.error("Check speed result with case \"%s\" failed." % case_name)
...@@ -217,4 +218,4 @@ if __name__ == "__main__": ...@@ -217,4 +218,4 @@ if __name__ == "__main__":
case_name, develop_result, pr_result, check_results 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 @@ ...@@ -16,6 +16,7 @@
import os import os
import os.path import os.path
import sys
from github import Github from github import Github
...@@ -36,11 +37,11 @@ class PRChecker: ...@@ -36,11 +37,11 @@ class PRChecker:
pr_id = os.getenv('GIT_PR_ID') pr_id = os.getenv('GIT_PR_ID')
if not pr_id: if not pr_id:
print('No PR ID') print('No PR ID')
exit(0) sys.exit(0)
print(pr_id) print(pr_id)
if not os.path.isfile(filename): if not os.path.isfile(filename):
print('No author to check') print('No author to check')
exit(0) sys.exit(0)
self.repo = self.github.get_repo('PaddlePaddle/Paddle') self.repo = self.github.get_repo('PaddlePaddle/Paddle')
pr = self.repo.get_pull(int(pr_id)) pr = self.repo.get_pull(int(pr_id))
user = pr.user.login user = pr.user.login
......
...@@ -107,7 +107,7 @@ while True: ...@@ -107,7 +107,7 @@ while True:
if not commits: if not commits:
sys.stdout.write('no commits to bisect\n') sys.stdout.write('no commits to bisect\n')
exit() sys.exit()
# checkout the picked branch. # checkout the picked branch.
pick_idx = len(commits) / 2 pick_idx = len(commits) / 2
pick = commits[pick_idx] pick = commits[pick_idx]
...@@ -129,7 +129,7 @@ while True: ...@@ -129,7 +129,7 @@ while True:
subprocess.check_output([cmd], shell=True) subprocess.check_output([cmd], shell=True)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
sys.stderr.write('failed to build commit: %s\n%s\n' % (pick, e)) sys.stderr.write('failed to build commit: %s\n%s\n' % (pick, e))
exit() sys.exit()
# test the selected branch. # test the selected branch.
passed = True passed = True
try: try:
......
...@@ -117,7 +117,7 @@ def get_info_file_lines(info_file, diff_file): ...@@ -117,7 +117,7 @@ def get_info_file_lines(info_file, diff_file):
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 3: if len(sys.argv) < 3:
exit() sys.exit()
info_file = sys.argv[1] info_file = sys.argv[1]
diff_file = sys.argv[2] diff_file = sys.argv[2]
......
...@@ -58,7 +58,7 @@ def filter_by(list_file, max_rate): ...@@ -58,7 +58,7 @@ def filter_by(list_file, max_rate):
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 2: if len(sys.argv) < 2:
exit() sys.exit()
list_file = sys.argv[1] list_file = sys.argv[1]
max_rate = float(sys.argv[2]) max_rate = float(sys.argv[2])
......
...@@ -47,21 +47,21 @@ def get_lines(info_file): ...@@ -47,21 +47,21 @@ def get_lines(info_file):
if total == 0: if total == 0:
print('no data found') print('no data found')
exit() sys.exit()
return hits / total return hits / total
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 3: if len(sys.argv) < 3:
exit() sys.exit()
info_file = sys.argv[1] info_file = sys.argv[1]
expected = float(sys.argv[2]) expected = float(sys.argv[2])
if not os.path.isfile(info_file): if not os.path.isfile(info_file):
print('info file {} is not exists, ignored'.format(info_file)) print('info file {} is not exists, ignored'.format(info_file))
exit() sys.exit()
actual = get_lines(info_file) actual = get_lines(info_file)
actual = round(actual, 3) actual = round(actual, 3)
...@@ -73,7 +73,7 @@ if __name__ == '__main__': ...@@ -73,7 +73,7 @@ if __name__ == '__main__':
) )
) )
exit(1) sys.exit(1)
print( print(
'expected >= {} %, actual {} %, passed'.format( 'expected >= {} %, actual {} %, passed'.format(
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import argparse import argparse
import os import os
import re import re
import sys
# port range (21200, 23000) is reserved for dist-ops # port range (21200, 23000) is reserved for dist-ops
...@@ -556,7 +557,7 @@ class CMakeGenerator: ...@@ -556,7 +557,7 @@ class CMakeGenerator:
print(e) print(e)
print(f"[ERROR FILE]: {current_work_dir}/testslist.csv") print(f"[ERROR FILE]: {current_work_dir}/testslist.csv")
print(f"[ERROR LINE {i+1}]: {line.strip()}") print(f"[ERROR LINE {i+1}]: {line.strip()}")
exit(1) sys.exit(1)
for sub in sub_dirs: for sub in sub_dirs:
cmds += f"add_subdirectory({sub})\n" cmds += f"add_subdirectory({sub})\n"
......
...@@ -19,6 +19,7 @@ import platform ...@@ -19,6 +19,7 @@ import platform
import re import re
import ssl import ssl
import subprocess import subprocess
import sys
import time import time
import urllib.request import urllib.request
...@@ -52,7 +53,7 @@ class PRChecker: ...@@ -52,7 +53,7 @@ class PRChecker:
pr_id = os.getenv('GIT_PR_ID') pr_id = os.getenv('GIT_PR_ID')
if not pr_id: if not pr_id:
print('PREC No PR ID') print('PREC No PR ID')
exit(0) sys.exit(0)
suffix = os.getenv('PREC_SUFFIX') suffix = os.getenv('PREC_SUFFIX')
if suffix: if suffix:
self.suffix = suffix self.suffix = suffix
...@@ -311,7 +312,7 @@ class PRChecker: ...@@ -311,7 +312,7 @@ class PRChecker:
) )
if not ret: if not ret:
print('PREC download file_ut.json failed') print('PREC download file_ut.json failed')
exit(1) sys.exit(1)
with open('ut_file_map.json') as jsonfile: with open('ut_file_map.json') as jsonfile:
file_ut_map = json.load(jsonfile) file_ut_map = json.load(jsonfile)
...@@ -371,7 +372,7 @@ class PRChecker: ...@@ -371,7 +372,7 @@ class PRChecker:
ut_list.append(ut.rstrip('\r\n')) ut_list.append(ut.rstrip('\r\n'))
else: else:
print('PREC download prec_delta failed') print('PREC download prec_delta failed')
exit(1) sys.exit(1)
PRECISION_TEST_Cases_ratio = format( PRECISION_TEST_Cases_ratio = format(
float(len(ut_list)) / float(self.get_all_count()), '.2f' float(len(ut_list)) / float(self.get_all_count()), '.2f'
) )
...@@ -484,7 +485,7 @@ class PRChecker: ...@@ -484,7 +485,7 @@ class PRChecker:
ut_list.append(ut.rstrip('\r\n')) ut_list.append(ut.rstrip('\r\n'))
else: else:
print('PREC download prec_delta failed') print('PREC download prec_delta failed')
exit(1) sys.exit(1)
print("hitMapFiles: %s" % hitMapFiles) print("hitMapFiles: %s" % hitMapFiles)
print("ipipe_log_param_PRECISION_TEST: true") print("ipipe_log_param_PRECISION_TEST: true")
print( print(
......
...@@ -432,7 +432,7 @@ def execute_samplecode(tfname): ...@@ -432,7 +432,7 @@ def execute_samplecode(tfname):
else: else:
logger.error("Error: fail to parse python version!") logger.error("Error: fail to parse python version!")
result = False result = False
exit(1) sys.exit(1)
logger.info("----example code check----") logger.info("----example code check----")
logger.info("executing sample code: %s", tfname) logger.info("executing sample code: %s", tfname)
...@@ -724,7 +724,7 @@ if __name__ == '__main__': ...@@ -724,7 +724,7 @@ if __name__ == '__main__':
filenames = get_filenames(args.full_test) filenames = get_filenames(args.full_test)
if len(filenames) == 0 and len(whl_error) == 0: if len(filenames) == 0 and len(whl_error) == 0:
logger.info("-----API_PR.spec is the same as API_DEV.spec-----") 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) logger.info("API_PR is diff from API_DEV: %s", filenames)
threads = multiprocessing.cpu_count() threads = multiprocessing.cpu_count()
...@@ -760,7 +760,7 @@ if __name__ == '__main__': ...@@ -760,7 +760,7 @@ if __name__ == '__main__':
"In addition, mistakes found in sample codes: %s", temp[1] "In addition, mistakes found in sample codes: %s", temp[1]
) )
logger.info("----------------------------------------------------") logger.info("----------------------------------------------------")
exit(1) sys.exit(1)
else: else:
timeovered_test = {} timeovered_test = {}
for temp in result: for temp in result:
...@@ -810,7 +810,7 @@ if __name__ == '__main__': ...@@ -810,7 +810,7 @@ if __name__ == '__main__':
logger.info( logger.info(
"Mistakes found in sample codes. Please recheck the sample codes." "Mistakes found in sample codes. Please recheck the sample codes."
) )
exit(1) sys.exit(1)
logger.info("Sample code check is successful!") logger.info("Sample code check is successful!")
......
...@@ -63,7 +63,7 @@ def main(): ...@@ -63,7 +63,7 @@ def main():
paddle.disable_static() paddle.disable_static()
if some_test_failed: if some_test_failed:
exit(1) sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册