File tree Expand file tree Collapse file tree 1 file changed +20
-14
lines changed
Expand file tree Collapse file tree 1 file changed +20
-14
lines changed Original file line number Diff line number Diff line change 1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616
17+ import threading
1718from contextlib import contextmanager
1819from os import environ , getenv
1920from platform import system as sys_platform
2526
2627_UNCHECKED = sys_platform () == "Linux"
2728del sys_platform
29+ _unchecked_lock = threading .Lock ()
2830
2931
3032@contextmanager
@@ -68,21 +70,25 @@ def onetrace_enabled():
6870 """
6971 global _UNCHECKED
7072
71- if _UNCHECKED :
72- _UNCHECKED = False
73- if not (
74- getenv ("PTI_ENABLE" , None ) == "1"
75- and "onetrace_tool" in getenv ("LD_PRELOAD" , "" )
76- ):
77- import warnings
78-
79- warnings .warn (
80- "It looks like Python interpreter was not started using "
81- "`onetrace` utility. Using `onetrace_enabled` may have "
82- "no effect. See `onetrace_enabled.__doc__` for usage." ,
83- RuntimeWarning ,
84- stacklevel = 2 ,
73+ with _unchecked_lock :
74+ if _UNCHECKED :
75+ _UNCHECKED = False
76+ needs_warning = not (
77+ getenv ("PTI_ENABLE" , None ) == "1"
78+ and "onetrace_tool" in getenv ("LD_PRELOAD" , "" )
8579 )
80+ else :
81+ needs_warning = False
82+ if needs_warning :
83+ import warnings
84+
85+ warnings .warn (
86+ "It looks like Python interpreter was not started using "
87+ "`onetrace` utility. Using `onetrace_enabled` may have "
88+ "no effect. See `onetrace_enabled.__doc__` for usage." ,
89+ RuntimeWarning ,
90+ stacklevel = 2 ,
91+ )
8692
8793 _env_var_name = "PTI_ENABLE_COLLECTION"
8894 saved = getenv (_env_var_name , None )
You can’t perform that action at this time.
0 commit comments