From 7472cb602a55a844f2f7cc8b139c85bc9327fda9 Mon Sep 17 00:00:00 2001 From: Ze Gan Date: Tue, 28 Nov 2023 19:33:00 +0800 Subject: [PATCH] Fix swsscommon import protobuf error ``` Current thread 0x00007f4ce5a01740 (most recent call first): File "", line 228 in _call_with_frames_removed File "", line 1108 in create_module File "", line 565 in module_from_spec File "", line 666 in _load_unlocked File "", line 986 in _find_and_load_unlocked File "", line 1007 in _find_and_load File "", line 228 in _call_with_frames_removed File "", line 1058 in _handle_fromlist File "/usr/lib/python3/dist-packages/swsscommon/swsscommon.py", line 13 in File "", line 228 in _call_with_frames_removed File "", line 790 in exec_module File "", line 680 in _load_unlocked File "", line 986 in _find_and_load_unlocked File "", line 1007 in _find_and_load File "", line 228 in _call_with_frames_removed File "", line 1058 in _handle_fromlist File "/sonic/src/sonic-platform-daemons/sonic-ycabled/tests/test_y_cable_helper.py", line 3 in File "/usr/lib/python3/dist-packages/_pytest/assertion/rewrite.py", line 170 in exec_module File "", line 680 in _load_unlocked File "", line 986 in _find_and_load_unlocked File "", line 1007 in _find_and_load File "", line 1030 in _gcd_import File "/usr/lib/python3.9/importlib/__init__.py", line 127 in import_module File "/usr/lib/python3/dist-packages/_pytest/pathlib.py", line 520 in import_path File "/usr/lib/python3/dist-packages/_pytest/python.py", line 552 in _importtestmodule File "/usr/lib/python3/dist-packages/_pytest/python.py", line 484 in _getobj File "/usr/lib/python3/dist-packages/_pytest/python.py", line 288 in obj File "/usr/lib/python3/dist-packages/_pytest/python.py", line 500 in _inject_setup_module_fixture File "/usr/lib/python3/dist-packages/_pytest/python.py", line 487 in collect File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 324 in File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 294 in from_call File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 324 in pytest_make_collect_report File "/usr/lib/python3/dist-packages/pluggy/callers.py", line 187 in _multicall File "/usr/lib/python3/dist-packages/pluggy/manager.py", line 83 in File "/usr/lib/python3/dist-packages/pluggy/manager.py", line 92 in _hookexec File "/usr/lib/python3/dist-packages/pluggy/hooks.py", line 286 in __call__ File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 441 in collect_one_node File "/usr/lib/python3/dist-packages/_pytest/main.py", line 768 in genitems File "/usr/lib/python3/dist-packages/_pytest/main.py", line 771 in genitems File "/usr/lib/python3/dist-packages/_pytest/main.py", line 568 in _perform_collect File "/usr/lib/python3/dist-packages/_pytest/main.py", line 516 in perform_collect File "/usr/lib/python3/dist-packages/_pytest/main.py", line 306 in pytest_collection File "/usr/lib/python3/dist-packages/pluggy/callers.py", line 187 in _multicall File "/usr/lib/python3/dist-packages/pluggy/manager.py", line 83 in File "/usr/lib/python3/dist-packages/pluggy/manager.py", line 92 in _hookexec File "/usr/lib/python3/dist-packages/pluggy/hooks.py", line 286 in __call__ File "/usr/lib/python3/dist-packages/_pytest/main.py", line 295 in _main File "/usr/lib/python3/dist-packages/_pytest/main.py", line 240 in wrap_session File "/usr/lib/python3/dist-packages/_pytest/main.py", line 289 in pytest_cmdline_main File "/usr/lib/python3/dist-packages/pluggy/callers.py", line 187 in _multicall File "/usr/lib/python3/dist-packages/pluggy/manager.py", line 83 in File "/usr/lib/python3/dist-packages/pluggy/manager.py", line 92 in _hookexec File "/usr/lib/python3/dist-packages/pluggy/hooks.py", line 286 in __call__ File "/usr/lib/python3/dist-packages/_pytest/config/__init__.py", line 157 in main File "/usr/local/lib/python3.9/dist-packages/ptr.py", line 220 in run_tests File "/usr/local/lib/python3.9/dist-packages/ptr.py", line 209 in run File "/usr/lib/python3.9/distutils/dist.py", line 985 in run_command File "/usr/lib/python3.9/distutils/dist.py", line 966 in run_commands File "/usr/lib/python3.9/distutils/core.py", line 148 in setup File "/usr/local/lib/python3.9/dist-packages/setuptools/__init__.py", line 163 in setup File "/sonic/src/sonic-platform-daemons/sonic-ycabled/setup.py", line 30 in Aborted (core dumped) ``` By GDB and get the error trace of protobuf like : ``` at assert.c:92 function=function@entry=0x7ffff7faa1c0 <__PRETTY_FUNCTION__.0> "__pthread_tpp_change_priority") at assert.c:101 ``` Signed-off-by: Ze Gan --- sonic-ycabled/setup.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sonic-ycabled/setup.py b/sonic-ycabled/setup.py index 60ee1414c..d45b60037 100644 --- a/sonic-ycabled/setup.py +++ b/sonic-ycabled/setup.py @@ -1,6 +1,15 @@ from setuptools import setup, find_packages from distutils.command.build_ext import build_ext as _build_ext import distutils.command +# The shared library of protobuf will be used in the swsscommon +# So, when we execute python setup.py test, the protobuf.so will be +# imported twice simultaneously in `GrpcTool run` and +# `test_y_cable_helper.py: from swsscommon import swsscommon`, +# The initialization of some global variables in protobuf.so will be conflicted +# so that raises an import error. +# To avoid this issue, we need to explicitly import swsscommon before +# above two steps. +from swsscommon import swsscommon class GrpcTool(distutils.cmd.Command): def initialize_options(self):