File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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
@@ -62,21 +64,25 @@ def onetrace_enabled():
6264 """
6365 global _UNCHECKED
6466
65- if _UNCHECKED :
66- _UNCHECKED = False
67- if not (
68- getenv ("PTI_ENABLE" , None ) == "1"
69- and "onetrace_tool" in getenv ("LD_PRELOAD" , "" )
70- ):
71- import warnings
72-
73- warnings .warn (
74- "It looks like Python interpreter was not started using "
75- "`onetrace` utility. Using `onetrace_enabled` may have "
76- "no effect. See `onetrace_enabled.__doc__` for usage." ,
77- RuntimeWarning ,
78- stacklevel = 2 ,
67+ with _unchecked_lock :
68+ if _UNCHECKED :
69+ _UNCHECKED = False
70+ needs_warning = not (
71+ getenv ("PTI_ENABLE" , None ) == "1"
72+ and "onetrace_tool" in getenv ("LD_PRELOAD" , "" )
7973 )
74+ else :
75+ needs_warning = False
76+ if needs_warning :
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 ,
85+ )
8086
8187 _env_var_name = "PTI_ENABLE_COLLECTION"
8288 saved = getenv (_env_var_name , None )
You can’t perform that action at this time.
0 commit comments