From 2979362e04c90eeba0618b431509789060e53ab1 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 2 Oct 2023 18:15:13 -0700 Subject: [PATCH] Remove all 3.7 checks --- src/viztracer/code_monkey.py | 6 +----- src/viztracer/patch.py | 22 ++-------------------- tests/test_cmdline.py | 1 - tests/test_multiprocess.py | 3 +-- 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/viztracer/code_monkey.py b/src/viztracer/code_monkey.py index bd51ffd5..e59e4a8c 100644 --- a/src/viztracer/code_monkey.py +++ b/src/viztracer/code_monkey.py @@ -40,11 +40,7 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> ast.FunctionDef: elif self.inst_type in ("log_var", "log_number"): instrumented_nodes: List[ast.stmt] = [] args = node.args - if sys.version_info >= (3, 8): - func_args_name = [a.arg for a in args.posonlyargs + args.args + args.kwonlyargs] - else: - # python 3.7 does not have posonlyargs - func_args_name = [a.arg for a in args.args + args.kwonlyargs] + func_args_name = [a.arg for a in args.posonlyargs + args.args + args.kwonlyargs] if "vararg" in args._fields and args.vararg: func_args_name.append(args.vararg.arg) if "kwarg" in args._fields and args.kwarg: diff --git a/src/viztracer/patch.py b/src/viztracer/patch.py index fc77cef1..c17bce8e 100644 --- a/src/viztracer/patch.py +++ b/src/viztracer/patch.py @@ -161,7 +161,7 @@ def patch_spawned_process(viztracer_kwargs: Dict[str, Any], cmdline_args: List[s @no_type_check @functools.wraps(multiprocessing.spawn._main) - def _main_3839(fd, parent_sentinel) -> Any: + def _main(fd, parent_sentinel) -> Any: with os.fdopen(fd, 'rb', closefd=True) as from_parent: process.current_process()._inheriting = True try: @@ -174,25 +174,7 @@ def _main_3839(fd, parent_sentinel) -> Any: del process.current_process()._inheriting return self._bootstrap(parent_sentinel) - @no_type_check - @functools.wraps(multiprocessing.spawn._main) - def _main_3637(fd) -> Any: - with os.fdopen(fd, 'rb', closefd=True) as from_parent: - process.current_process()._inheriting = True - try: - preparation_data = reduction.pickle.load(from_parent) - prepare(preparation_data) - self: Process = reduction.pickle.load(from_parent) - sp = SpawnProcess(viztracer_kwargs, self.run, self._target, self._args, self._kwargs, cmdline_args) - self.run = sp.run - finally: - del process.current_process()._inheriting - return self._bootstrap() - - if sys.version_info >= (3, 8): - multiprocessing.spawn._main = _main_3839 # type: ignore - else: - multiprocessing.spawn._main = _main_3637 # type: ignore + multiprocessing.spawn._main = _main # type: ignore def install_all_hooks( diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 3c49d8ba..b421d943 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -406,7 +406,6 @@ def test_log_func_entry(self): expected_output_file="result.json", expected_entries=7) - @skipIf(sys.version_info < (3, 8), "sys.addaudithook does not exist on 3.8-") def test_log_audit(self): def check_func(include_names, exclude_names=[]): def inner(data): diff --git a/tests/test_multiprocess.py b/tests/test_multiprocess.py index a9b2534a..7a154c8d 100644 --- a/tests/test_multiprocess.py +++ b/tests/test_multiprocess.py @@ -292,7 +292,7 @@ def check_func(data): self.template(["viztracer", "-o", "result.json", "cmdline_test.py"], expected_output_file="result.json", script=file_fork, check_func=check_func) - @unittest.skipIf(sys.version_info < (3, 8) or sys.platform not in ["linux", "linux2"], "Only works on Linux + py3.8+") + @unittest.skipIf(sys.platform not in ["linux", "linux2"], "Only works on Linux") def test_os_fork_term(self): def check_func_wrapper(process_num): def check_func(data): @@ -408,7 +408,6 @@ def check_func(data): class TestLoky(CmdlineTmpl): - @skipIf(sys.version_info < (3, 8), "fork + exec will make viztracer + loky deadlock") def test_loky_basic(self): def check_func(data): pids = set()