We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Upgrade `pylint` to  `2.14.4`
We currently use pylint 2.11.1. This is a bit old so we should upgrade it to the latest version (2.14.4):

https://github.com/mlflow/mlflow/blob/d40780be361f4bd2741c2e8fcbd428c1d693edcf/requirements/lint-requirements.txt#L1

- https://pypi.org/project/pylint/2.11.1/
- https://pypi.org/project/pylint/2.14.4/

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mlflow/utils/autologging_utils/logging_and_warnings.py`
Content:
```
1 import os
2 import warnings
3 from contextlib import contextmanager
4 from pathlib import Path
5 from threading import RLock, get_ident as get_current_thread_id
6 
7 import mlflow
8 import mlflow.utils.logging_utils as logging_utils
9 
10 
11 class _WarningsController:
12     """
13     Provides threadsafe utilities to modify warning behavior for MLflow autologging, including:
14 
15     - Global disablement of MLflow warnings across all threads
16     - Global rerouting of MLflow warnings to an MLflow event logger (i.e. `logger.warn()`)
17       across all threads
18     - Disablement of non-MLflow warnings for the current thread
19     - Rerouting of non-MLflow warnings to an MLflow event logger for the current thread
20     """
21 
22     def __init__(self):
23         self._mlflow_root_path = Path(os.path.dirname(mlflow.__file__)).resolve()
24         self._state_lock = RLock()
25 
26         self._did_patch_showwarning = False
27         self._original_showwarning = None
28 
29         self._disabled_threads = set()
30         self._rerouted_threads = set()
31         self._mlflow_warnings_disabled_globally = False
32         self._mlflow_warnings_rerouted_to_event_logs = False
33 
34     def _patched_showwarning(self, message, category, filename, lineno, *args, **kwargs):
35         """
36         A patched implementation of `warnings.showwarning` that enforces the warning configuration
37         options configured on the controller (e.g. rerouting or disablement of MLflow warnings,
38         disablement of all warnings for the current thread).
39 
40         Note that reassigning `warnings.showwarning` is the standard / recommended approach for
41         modifying warning message display behaviors. For reference, see
42         https://docs.python.org/3/library/warnings.html#warnings.showwarning
43         """
44         # NB: We explicitly avoid blocking on the `self._state_lock` lock during `showwarning`
45         # to so that threads don't have to execute serially whenever they emit warnings with
46         # `warnings.warn()`. We only lock during configuration changes to ensure that
47         # `warnings.showwarning` is patched or unpatched at the correct times.
48 
49         from mlflow.utils.autologging_utils import _logger
50 
51         # If the warning's source file is contained within the MLflow package's base
52         # directory, it is an MLflow warning and should be emitted via `logger.warning`
53         warning_source_path = Path(filename).resolve()
54         is_mlflow_warning = self._mlflow_root_path in warning_source_path.parents
55         curr_thread = get_current_thread_id()
56 
57         if (curr_thread in self._disabled_threads) or (
58             is_mlflow_warning and self._mlflow_warnings_disabled_globally
59         ):
60             return
61         elif (curr_thread in self._rerouted_threads and not is_mlflow_warning) or (
62             is_mlflow_warning and self._mlflow_warnings_rerouted_to_event_logs
63         ):
64             _logger.warning(
65                 "MLflow autologging encountered a warning:" ' "%s:%d: %s: %s"',
66                 filename,
67                 lineno,
68                 category.__name__,
69                 message,
70             )
71         else:
72             self._original_showwarning(message, category, filename, lineno, *args, **kwargs)
73 
74     def _should_patch_showwarning(self):
75         return (
76             (len(self._disabled_threads) > 0)
77             or (len(self._rerouted_threads) > 0)
78             or self._mlflow_warnings_disabled_globally
79             or self._mlflow_warnings_rerouted_to_event_logs
80         )
81 
82     def _modify_patch_state_if_necessary(self):
83         """
84         Patches or unpatches `warnings.showwarning` if necessary, as determined by:
85             - Whether or not `warnings.showwarning` is already patched
86             - Whether or not any custom warning state has been configured on the warnings
87               controller (i.e. disablement or rerouting of certain warnings globally or for a
88               particular thread)
89 
90         Note that reassigning `warnings.showwarning` is the standard / recommended approach for
91         modifying warning message display behaviors. For reference, see
92         https://docs.python.org/3/library/warnings.html#warnings.showwarning
93         """
94         with self._state_lock:
95             if self._should_patch_showwarning() and not self._did_patch_showwarning:
96                 self._original_showwarning = warnings.showwarning
97                 warnings.showwarning = self._patched_showwarning
98                 self._did_patch_showwarning = True
99             elif not self._should_patch_showwarning() and self._did_patch_showwarning:
100                 warnings.showwarning = self._original_showwarning
101                 self._did_patch_showwarning = False
102 
103     def set_mlflow_warnings_disablement_state_globally(self, disabled=True):
104         """
105         Disables (or re-enables) MLflow warnings globally across all threads.
106 
107         :param disabled: If `True`, disables MLflow warnings globally across all threads.
108                          If `False`, enables MLflow warnings globally across all threads.
109         """
110         with self._state_lock:
111             self._mlflow_warnings_disabled_globally = disabled
112             self._modify_patch_state_if_necessary()
113 
114     def set_mlflow_warnings_rerouting_state_globally(self, rerouted=True):
115         """
116         Enables (or disables) rerouting of MLflow warnings to an MLflow event logger with level
117         WARNING (e.g. `logger.warning()`) globally across all threads.
118 
119         :param rerouted: If `True`, enables MLflow warning rerouting globally across all threads.
120                          If `False`, disables MLflow warning rerouting globally across all threads.
121         """
122         with self._state_lock:
123             self._mlflow_warnings_rerouted_to_event_logs = rerouted
124             self._modify_patch_state_if_necessary()
125 
126     def set_non_mlflow_warnings_disablement_state_for_current_thread(self, disabled=True):
127         """
128         Disables (or re-enables) non-MLflow warnings for the current thread.
129 
130         :param disabled: If `True`, disables non-MLflow warnings for the current thread. If `False`,
131                          enables non-MLflow warnings for the current thread. non-MLflow warning
132                          behavior in other threads is unaffected.
133         """
134         with self._state_lock:
135             if disabled:
136                 self._disabled_threads.add(get_current_thread_id())
137             else:
138                 self._disabled_threads.discard(get_current_thread_id())
139             self._modify_patch_state_if_necessary()
140 
141     def set_non_mlflow_warnings_rerouting_state_for_current_thread(self, rerouted=True):
142         """
143         Enables (or disables) rerouting of non-MLflow warnings to an MLflow event logger with level
144         WARNING (e.g. `logger.warning()`) for the current thread.
145 
146         :param rerouted: If `True`, enables non-MLflow warning rerouting for the current thread.
147                          If `False`, disables non-MLflow warning rerouting for the current thread.
148                          non-MLflow warning behavior in other threads is unaffected.
149         """
150         with self._state_lock:
151             if rerouted:
152                 self._rerouted_threads.add(get_current_thread_id())
153             else:
154                 self._rerouted_threads.discard(get_current_thread_id())
155             self._modify_patch_state_if_necessary()
156 
157     def get_warnings_disablement_state_for_current_thread(self):
158         """
159         :return: `True` if non-MLflow warnings are disabled for the current thread.
160                  `False` otherwise.
161         """
162         return get_current_thread_id() in self._disabled_threads
163 
164     def get_warnings_rerouting_state_for_current_thread(self):
165         """
166         :return: `True` if non-MLflow warnings are rerouted to an MLflow event logger with level
167                  WARNING for the current thread. `False` otherwise.
168         """
169         return get_current_thread_id() in self._rerouted_threads
170 
171 
172 _WARNINGS_CONTROLLER = _WarningsController()
173 
174 
175 @contextmanager
176 def set_non_mlflow_warnings_behavior_for_current_thread(disable_warnings, reroute_warnings):
177     """
178     Context manager that modifies the behavior of non-MLflow warnings upon entry, according to the
179     specified parameters.
180 
181     :param disable_warnings: If `True`, disable  (mutate & discard) non-MLflow warnings. If `False`,
182                              do not disable non-MLflow warnings.
183     :param reroute_warnings: If `True`, reroute non-MLflow warnings to an MLflow event logger with
184                              level WARNING. If `False`, do not reroute non-MLflow warnings.
185     """
186     prev_disablement_state = (
187         _WARNINGS_CONTROLLER.get_warnings_disablement_state_for_current_thread()
188     )
189     prev_rerouting_state = _WARNINGS_CONTROLLER.get_warnings_rerouting_state_for_current_thread()
190     try:
191         _WARNINGS_CONTROLLER.set_non_mlflow_warnings_disablement_state_for_current_thread(
192             disabled=disable_warnings
193         )
194         _WARNINGS_CONTROLLER.set_non_mlflow_warnings_rerouting_state_for_current_thread(
195             rerouted=reroute_warnings
196         )
197         yield
198     finally:
199         _WARNINGS_CONTROLLER.set_non_mlflow_warnings_disablement_state_for_current_thread(
200             disabled=prev_disablement_state
201         )
202         _WARNINGS_CONTROLLER.set_non_mlflow_warnings_rerouting_state_for_current_thread(
203             rerouted=prev_rerouting_state
204         )
205 
206 
207 @contextmanager
208 def set_mlflow_events_and_warnings_behavior_globally(
209     disable_event_logs, disable_warnings, reroute_warnings
210 ):
211     """
212     Threadsafe context manager that modifies the behavior of MLflow event logging statements
213     and MLflow warnings upon entry, according to the specified parameters. Modifications are
214     applied globally across all threads and are not reverted until all threads that have made
215     a particular modification have exited the context.
216 
217     :param disable_event_logs: If `True`, disable (mute & discard) MLflow event logging statements.
218                                If `False`, do not disable MLflow event logging statements.
219     :param disable_warnings: If `True`, disable  (mutate & discard) MLflow warnings. If `False`,
220                              do not disable MLflow warnings.
221     :param reroute_warnings: If `True`, reroute MLflow warnings to an MLflow event logger with
222                              level WARNING. If `False`, do not reroute MLflow warnings.
223     """
224 
225     with _SetMLflowEventsAndWarningsBehaviorGlobally(
226         disable_event_logs, disable_warnings, reroute_warnings
227     ):
228         yield
229 
230 
231 class _SetMLflowEventsAndWarningsBehaviorGlobally:
232     _lock = RLock()
233     _disable_event_logs_count = 0
234     _disable_warnings_count = 0
235     _reroute_warnings_count = 0
236 
237     def __init__(self, disable_event_logs, disable_warnings, reroute_warnings):
238         self._disable_event_logs = disable_event_logs
239         self._disable_warnings = disable_warnings
240         self._reroute_warnings = reroute_warnings
241 
242     def __enter__(self):
243         try:
244             with _SetMLflowEventsAndWarningsBehaviorGlobally._lock:
245                 if self._disable_event_logs:
246                     if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count <= 0:
247                         logging_utils.disable_logging()
248                     _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count += 1
249 
250                 if self._disable_warnings:
251                     if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count <= 0:
252                         _WARNINGS_CONTROLLER.set_mlflow_warnings_disablement_state_globally(
253                             disabled=True
254                         )
255                     _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count += 1
256 
257                 if self._reroute_warnings:
258                     if _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count <= 0:
259                         _WARNINGS_CONTROLLER.set_mlflow_warnings_rerouting_state_globally(
260                             rerouted=True
261                         )
262                     _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count += 1
263         except Exception:
264             pass
265 
266     def __exit__(self, *args, **kwargs):
267         try:
268             with _SetMLflowEventsAndWarningsBehaviorGlobally._lock:
269                 if self._disable_event_logs:
270                     _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count -= 1
271                 if self._disable_warnings:
272                     _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count -= 1
273                 if self._reroute_warnings:
274                     _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count -= 1
275 
276                 if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count <= 0:
277                     logging_utils.enable_logging()
278                 if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count <= 0:
279                     _WARNINGS_CONTROLLER.set_mlflow_warnings_disablement_state_globally(
280                         disabled=False
281                     )
282                 if _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count <= 0:
283                     _WARNINGS_CONTROLLER.set_mlflow_warnings_rerouting_state_globally(
284                         rerouted=False
285                     )
286         except Exception:
287             pass
288
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mlflow/utils/autologging_utils/logging_and_warnings.py b/mlflow/utils/autologging_utils/logging_and_warnings.py
--- a/mlflow/utils/autologging_utils/logging_and_warnings.py
+++ b/mlflow/utils/autologging_utils/logging_and_warnings.py
@@ -62,7 +62,7 @@
             is_mlflow_warning and self._mlflow_warnings_rerouted_to_event_logs
         ):
             _logger.warning(
-                "MLflow autologging encountered a warning:" ' "%s:%d: %s: %s"',
+                'MLflow autologging encountered a warning: "%s:%d: %s: %s"',
                 filename,
                 lineno,
                 category.__name__,

{"golden_diff": "diff --git a/mlflow/utils/autologging_utils/logging_and_warnings.py b/mlflow/utils/autologging_utils/logging_and_warnings.py\n--- a/mlflow/utils/autologging_utils/logging_and_warnings.py\n+++ b/mlflow/utils/autologging_utils/logging_and_warnings.py\n@@ -62,7 +62,7 @@\n             is_mlflow_warning and self._mlflow_warnings_rerouted_to_event_logs\n         ):\n             _logger.warning(\n-                \"MLflow autologging encountered a warning:\" ' \"%s:%d: %s: %s\"',\n+                'MLflow autologging encountered a warning: \"%s:%d: %s: %s\"',\n                 filename,\n                 lineno,\n                 category.__name__,\n", "issue": "Upgrade `pylint` to  `2.14.4`\nWe currently use pylint 2.11.1. This is a bit old so we should upgrade it to the latest version (2.14.4):\r\n\r\nhttps://github.com/mlflow/mlflow/blob/d40780be361f4bd2741c2e8fcbd428c1d693edcf/requirements/lint-requirements.txt#L1\r\n\r\n- https://pypi.org/project/pylint/2.11.1/\r\n- https://pypi.org/project/pylint/2.14.4/\n", "before_files": [{"content": "import os\nimport warnings\nfrom contextlib import contextmanager\nfrom pathlib import Path\nfrom threading import RLock, get_ident as get_current_thread_id\n\nimport mlflow\nimport mlflow.utils.logging_utils as logging_utils\n\n\nclass _WarningsController:\n    \"\"\"\n    Provides threadsafe utilities to modify warning behavior for MLflow autologging, including:\n\n    - Global disablement of MLflow warnings across all threads\n    - Global rerouting of MLflow warnings to an MLflow event logger (i.e. `logger.warn()`)\n      across all threads\n    - Disablement of non-MLflow warnings for the current thread\n    - Rerouting of non-MLflow warnings to an MLflow event logger for the current thread\n    \"\"\"\n\n    def __init__(self):\n        self._mlflow_root_path = Path(os.path.dirname(mlflow.__file__)).resolve()\n        self._state_lock = RLock()\n\n        self._did_patch_showwarning = False\n        self._original_showwarning = None\n\n        self._disabled_threads = set()\n        self._rerouted_threads = set()\n        self._mlflow_warnings_disabled_globally = False\n        self._mlflow_warnings_rerouted_to_event_logs = False\n\n    def _patched_showwarning(self, message, category, filename, lineno, *args, **kwargs):\n        \"\"\"\n        A patched implementation of `warnings.showwarning` that enforces the warning configuration\n        options configured on the controller (e.g. rerouting or disablement of MLflow warnings,\n        disablement of all warnings for the current thread).\n\n        Note that reassigning `warnings.showwarning` is the standard / recommended approach for\n        modifying warning message display behaviors. For reference, see\n        https://docs.python.org/3/library/warnings.html#warnings.showwarning\n        \"\"\"\n        # NB: We explicitly avoid blocking on the `self._state_lock` lock during `showwarning`\n        # to so that threads don't have to execute serially whenever they emit warnings with\n        # `warnings.warn()`. We only lock during configuration changes to ensure that\n        # `warnings.showwarning` is patched or unpatched at the correct times.\n\n        from mlflow.utils.autologging_utils import _logger\n\n        # If the warning's source file is contained within the MLflow package's base\n        # directory, it is an MLflow warning and should be emitted via `logger.warning`\n        warning_source_path = Path(filename).resolve()\n        is_mlflow_warning = self._mlflow_root_path in warning_source_path.parents\n        curr_thread = get_current_thread_id()\n\n        if (curr_thread in self._disabled_threads) or (\n            is_mlflow_warning and self._mlflow_warnings_disabled_globally\n        ):\n            return\n        elif (curr_thread in self._rerouted_threads and not is_mlflow_warning) or (\n            is_mlflow_warning and self._mlflow_warnings_rerouted_to_event_logs\n        ):\n            _logger.warning(\n                \"MLflow autologging encountered a warning:\" ' \"%s:%d: %s: %s\"',\n                filename,\n                lineno,\n                category.__name__,\n                message,\n            )\n        else:\n            self._original_showwarning(message, category, filename, lineno, *args, **kwargs)\n\n    def _should_patch_showwarning(self):\n        return (\n            (len(self._disabled_threads) > 0)\n            or (len(self._rerouted_threads) > 0)\n            or self._mlflow_warnings_disabled_globally\n            or self._mlflow_warnings_rerouted_to_event_logs\n        )\n\n    def _modify_patch_state_if_necessary(self):\n        \"\"\"\n        Patches or unpatches `warnings.showwarning` if necessary, as determined by:\n            - Whether or not `warnings.showwarning` is already patched\n            - Whether or not any custom warning state has been configured on the warnings\n              controller (i.e. disablement or rerouting of certain warnings globally or for a\n              particular thread)\n\n        Note that reassigning `warnings.showwarning` is the standard / recommended approach for\n        modifying warning message display behaviors. For reference, see\n        https://docs.python.org/3/library/warnings.html#warnings.showwarning\n        \"\"\"\n        with self._state_lock:\n            if self._should_patch_showwarning() and not self._did_patch_showwarning:\n                self._original_showwarning = warnings.showwarning\n                warnings.showwarning = self._patched_showwarning\n                self._did_patch_showwarning = True\n            elif not self._should_patch_showwarning() and self._did_patch_showwarning:\n                warnings.showwarning = self._original_showwarning\n                self._did_patch_showwarning = False\n\n    def set_mlflow_warnings_disablement_state_globally(self, disabled=True):\n        \"\"\"\n        Disables (or re-enables) MLflow warnings globally across all threads.\n\n        :param disabled: If `True`, disables MLflow warnings globally across all threads.\n                         If `False`, enables MLflow warnings globally across all threads.\n        \"\"\"\n        with self._state_lock:\n            self._mlflow_warnings_disabled_globally = disabled\n            self._modify_patch_state_if_necessary()\n\n    def set_mlflow_warnings_rerouting_state_globally(self, rerouted=True):\n        \"\"\"\n        Enables (or disables) rerouting of MLflow warnings to an MLflow event logger with level\n        WARNING (e.g. `logger.warning()`) globally across all threads.\n\n        :param rerouted: If `True`, enables MLflow warning rerouting globally across all threads.\n                         If `False`, disables MLflow warning rerouting globally across all threads.\n        \"\"\"\n        with self._state_lock:\n            self._mlflow_warnings_rerouted_to_event_logs = rerouted\n            self._modify_patch_state_if_necessary()\n\n    def set_non_mlflow_warnings_disablement_state_for_current_thread(self, disabled=True):\n        \"\"\"\n        Disables (or re-enables) non-MLflow warnings for the current thread.\n\n        :param disabled: If `True`, disables non-MLflow warnings for the current thread. If `False`,\n                         enables non-MLflow warnings for the current thread. non-MLflow warning\n                         behavior in other threads is unaffected.\n        \"\"\"\n        with self._state_lock:\n            if disabled:\n                self._disabled_threads.add(get_current_thread_id())\n            else:\n                self._disabled_threads.discard(get_current_thread_id())\n            self._modify_patch_state_if_necessary()\n\n    def set_non_mlflow_warnings_rerouting_state_for_current_thread(self, rerouted=True):\n        \"\"\"\n        Enables (or disables) rerouting of non-MLflow warnings to an MLflow event logger with level\n        WARNING (e.g. `logger.warning()`) for the current thread.\n\n        :param rerouted: If `True`, enables non-MLflow warning rerouting for the current thread.\n                         If `False`, disables non-MLflow warning rerouting for the current thread.\n                         non-MLflow warning behavior in other threads is unaffected.\n        \"\"\"\n        with self._state_lock:\n            if rerouted:\n                self._rerouted_threads.add(get_current_thread_id())\n            else:\n                self._rerouted_threads.discard(get_current_thread_id())\n            self._modify_patch_state_if_necessary()\n\n    def get_warnings_disablement_state_for_current_thread(self):\n        \"\"\"\n        :return: `True` if non-MLflow warnings are disabled for the current thread.\n                 `False` otherwise.\n        \"\"\"\n        return get_current_thread_id() in self._disabled_threads\n\n    def get_warnings_rerouting_state_for_current_thread(self):\n        \"\"\"\n        :return: `True` if non-MLflow warnings are rerouted to an MLflow event logger with level\n                 WARNING for the current thread. `False` otherwise.\n        \"\"\"\n        return get_current_thread_id() in self._rerouted_threads\n\n\n_WARNINGS_CONTROLLER = _WarningsController()\n\n\n@contextmanager\ndef set_non_mlflow_warnings_behavior_for_current_thread(disable_warnings, reroute_warnings):\n    \"\"\"\n    Context manager that modifies the behavior of non-MLflow warnings upon entry, according to the\n    specified parameters.\n\n    :param disable_warnings: If `True`, disable  (mutate & discard) non-MLflow warnings. If `False`,\n                             do not disable non-MLflow warnings.\n    :param reroute_warnings: If `True`, reroute non-MLflow warnings to an MLflow event logger with\n                             level WARNING. If `False`, do not reroute non-MLflow warnings.\n    \"\"\"\n    prev_disablement_state = (\n        _WARNINGS_CONTROLLER.get_warnings_disablement_state_for_current_thread()\n    )\n    prev_rerouting_state = _WARNINGS_CONTROLLER.get_warnings_rerouting_state_for_current_thread()\n    try:\n        _WARNINGS_CONTROLLER.set_non_mlflow_warnings_disablement_state_for_current_thread(\n            disabled=disable_warnings\n        )\n        _WARNINGS_CONTROLLER.set_non_mlflow_warnings_rerouting_state_for_current_thread(\n            rerouted=reroute_warnings\n        )\n        yield\n    finally:\n        _WARNINGS_CONTROLLER.set_non_mlflow_warnings_disablement_state_for_current_thread(\n            disabled=prev_disablement_state\n        )\n        _WARNINGS_CONTROLLER.set_non_mlflow_warnings_rerouting_state_for_current_thread(\n            rerouted=prev_rerouting_state\n        )\n\n\n@contextmanager\ndef set_mlflow_events_and_warnings_behavior_globally(\n    disable_event_logs, disable_warnings, reroute_warnings\n):\n    \"\"\"\n    Threadsafe context manager that modifies the behavior of MLflow event logging statements\n    and MLflow warnings upon entry, according to the specified parameters. Modifications are\n    applied globally across all threads and are not reverted until all threads that have made\n    a particular modification have exited the context.\n\n    :param disable_event_logs: If `True`, disable (mute & discard) MLflow event logging statements.\n                               If `False`, do not disable MLflow event logging statements.\n    :param disable_warnings: If `True`, disable  (mutate & discard) MLflow warnings. If `False`,\n                             do not disable MLflow warnings.\n    :param reroute_warnings: If `True`, reroute MLflow warnings to an MLflow event logger with\n                             level WARNING. If `False`, do not reroute MLflow warnings.\n    \"\"\"\n\n    with _SetMLflowEventsAndWarningsBehaviorGlobally(\n        disable_event_logs, disable_warnings, reroute_warnings\n    ):\n        yield\n\n\nclass _SetMLflowEventsAndWarningsBehaviorGlobally:\n    _lock = RLock()\n    _disable_event_logs_count = 0\n    _disable_warnings_count = 0\n    _reroute_warnings_count = 0\n\n    def __init__(self, disable_event_logs, disable_warnings, reroute_warnings):\n        self._disable_event_logs = disable_event_logs\n        self._disable_warnings = disable_warnings\n        self._reroute_warnings = reroute_warnings\n\n    def __enter__(self):\n        try:\n            with _SetMLflowEventsAndWarningsBehaviorGlobally._lock:\n                if self._disable_event_logs:\n                    if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count <= 0:\n                        logging_utils.disable_logging()\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count += 1\n\n                if self._disable_warnings:\n                    if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count <= 0:\n                        _WARNINGS_CONTROLLER.set_mlflow_warnings_disablement_state_globally(\n                            disabled=True\n                        )\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count += 1\n\n                if self._reroute_warnings:\n                    if _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count <= 0:\n                        _WARNINGS_CONTROLLER.set_mlflow_warnings_rerouting_state_globally(\n                            rerouted=True\n                        )\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count += 1\n        except Exception:\n            pass\n\n    def __exit__(self, *args, **kwargs):\n        try:\n            with _SetMLflowEventsAndWarningsBehaviorGlobally._lock:\n                if self._disable_event_logs:\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count -= 1\n                if self._disable_warnings:\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count -= 1\n                if self._reroute_warnings:\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count -= 1\n\n                if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count <= 0:\n                    logging_utils.enable_logging()\n                if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count <= 0:\n                    _WARNINGS_CONTROLLER.set_mlflow_warnings_disablement_state_globally(\n                        disabled=False\n                    )\n                if _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count <= 0:\n                    _WARNINGS_CONTROLLER.set_mlflow_warnings_rerouting_state_globally(\n                        rerouted=False\n                    )\n        except Exception:\n            pass\n", "path": "mlflow/utils/autologging_utils/logging_and_warnings.py"}], "after_files": [{"content": "import os\nimport warnings\nfrom contextlib import contextmanager\nfrom pathlib import Path\nfrom threading import RLock, get_ident as get_current_thread_id\n\nimport mlflow\nimport mlflow.utils.logging_utils as logging_utils\n\n\nclass _WarningsController:\n    \"\"\"\n    Provides threadsafe utilities to modify warning behavior for MLflow autologging, including:\n\n    - Global disablement of MLflow warnings across all threads\n    - Global rerouting of MLflow warnings to an MLflow event logger (i.e. `logger.warn()`)\n      across all threads\n    - Disablement of non-MLflow warnings for the current thread\n    - Rerouting of non-MLflow warnings to an MLflow event logger for the current thread\n    \"\"\"\n\n    def __init__(self):\n        self._mlflow_root_path = Path(os.path.dirname(mlflow.__file__)).resolve()\n        self._state_lock = RLock()\n\n        self._did_patch_showwarning = False\n        self._original_showwarning = None\n\n        self._disabled_threads = set()\n        self._rerouted_threads = set()\n        self._mlflow_warnings_disabled_globally = False\n        self._mlflow_warnings_rerouted_to_event_logs = False\n\n    def _patched_showwarning(self, message, category, filename, lineno, *args, **kwargs):\n        \"\"\"\n        A patched implementation of `warnings.showwarning` that enforces the warning configuration\n        options configured on the controller (e.g. rerouting or disablement of MLflow warnings,\n        disablement of all warnings for the current thread).\n\n        Note that reassigning `warnings.showwarning` is the standard / recommended approach for\n        modifying warning message display behaviors. For reference, see\n        https://docs.python.org/3/library/warnings.html#warnings.showwarning\n        \"\"\"\n        # NB: We explicitly avoid blocking on the `self._state_lock` lock during `showwarning`\n        # to so that threads don't have to execute serially whenever they emit warnings with\n        # `warnings.warn()`. We only lock during configuration changes to ensure that\n        # `warnings.showwarning` is patched or unpatched at the correct times.\n\n        from mlflow.utils.autologging_utils import _logger\n\n        # If the warning's source file is contained within the MLflow package's base\n        # directory, it is an MLflow warning and should be emitted via `logger.warning`\n        warning_source_path = Path(filename).resolve()\n        is_mlflow_warning = self._mlflow_root_path in warning_source_path.parents\n        curr_thread = get_current_thread_id()\n\n        if (curr_thread in self._disabled_threads) or (\n            is_mlflow_warning and self._mlflow_warnings_disabled_globally\n        ):\n            return\n        elif (curr_thread in self._rerouted_threads and not is_mlflow_warning) or (\n            is_mlflow_warning and self._mlflow_warnings_rerouted_to_event_logs\n        ):\n            _logger.warning(\n                'MLflow autologging encountered a warning: \"%s:%d: %s: %s\"',\n                filename,\n                lineno,\n                category.__name__,\n                message,\n            )\n        else:\n            self._original_showwarning(message, category, filename, lineno, *args, **kwargs)\n\n    def _should_patch_showwarning(self):\n        return (\n            (len(self._disabled_threads) > 0)\n            or (len(self._rerouted_threads) > 0)\n            or self._mlflow_warnings_disabled_globally\n            or self._mlflow_warnings_rerouted_to_event_logs\n        )\n\n    def _modify_patch_state_if_necessary(self):\n        \"\"\"\n        Patches or unpatches `warnings.showwarning` if necessary, as determined by:\n            - Whether or not `warnings.showwarning` is already patched\n            - Whether or not any custom warning state has been configured on the warnings\n              controller (i.e. disablement or rerouting of certain warnings globally or for a\n              particular thread)\n\n        Note that reassigning `warnings.showwarning` is the standard / recommended approach for\n        modifying warning message display behaviors. For reference, see\n        https://docs.python.org/3/library/warnings.html#warnings.showwarning\n        \"\"\"\n        with self._state_lock:\n            if self._should_patch_showwarning() and not self._did_patch_showwarning:\n                self._original_showwarning = warnings.showwarning\n                warnings.showwarning = self._patched_showwarning\n                self._did_patch_showwarning = True\n            elif not self._should_patch_showwarning() and self._did_patch_showwarning:\n                warnings.showwarning = self._original_showwarning\n                self._did_patch_showwarning = False\n\n    def set_mlflow_warnings_disablement_state_globally(self, disabled=True):\n        \"\"\"\n        Disables (or re-enables) MLflow warnings globally across all threads.\n\n        :param disabled: If `True`, disables MLflow warnings globally across all threads.\n                         If `False`, enables MLflow warnings globally across all threads.\n        \"\"\"\n        with self._state_lock:\n            self._mlflow_warnings_disabled_globally = disabled\n            self._modify_patch_state_if_necessary()\n\n    def set_mlflow_warnings_rerouting_state_globally(self, rerouted=True):\n        \"\"\"\n        Enables (or disables) rerouting of MLflow warnings to an MLflow event logger with level\n        WARNING (e.g. `logger.warning()`) globally across all threads.\n\n        :param rerouted: If `True`, enables MLflow warning rerouting globally across all threads.\n                         If `False`, disables MLflow warning rerouting globally across all threads.\n        \"\"\"\n        with self._state_lock:\n            self._mlflow_warnings_rerouted_to_event_logs = rerouted\n            self._modify_patch_state_if_necessary()\n\n    def set_non_mlflow_warnings_disablement_state_for_current_thread(self, disabled=True):\n        \"\"\"\n        Disables (or re-enables) non-MLflow warnings for the current thread.\n\n        :param disabled: If `True`, disables non-MLflow warnings for the current thread. If `False`,\n                         enables non-MLflow warnings for the current thread. non-MLflow warning\n                         behavior in other threads is unaffected.\n        \"\"\"\n        with self._state_lock:\n            if disabled:\n                self._disabled_threads.add(get_current_thread_id())\n            else:\n                self._disabled_threads.discard(get_current_thread_id())\n            self._modify_patch_state_if_necessary()\n\n    def set_non_mlflow_warnings_rerouting_state_for_current_thread(self, rerouted=True):\n        \"\"\"\n        Enables (or disables) rerouting of non-MLflow warnings to an MLflow event logger with level\n        WARNING (e.g. `logger.warning()`) for the current thread.\n\n        :param rerouted: If `True`, enables non-MLflow warning rerouting for the current thread.\n                         If `False`, disables non-MLflow warning rerouting for the current thread.\n                         non-MLflow warning behavior in other threads is unaffected.\n        \"\"\"\n        with self._state_lock:\n            if rerouted:\n                self._rerouted_threads.add(get_current_thread_id())\n            else:\n                self._rerouted_threads.discard(get_current_thread_id())\n            self._modify_patch_state_if_necessary()\n\n    def get_warnings_disablement_state_for_current_thread(self):\n        \"\"\"\n        :return: `True` if non-MLflow warnings are disabled for the current thread.\n                 `False` otherwise.\n        \"\"\"\n        return get_current_thread_id() in self._disabled_threads\n\n    def get_warnings_rerouting_state_for_current_thread(self):\n        \"\"\"\n        :return: `True` if non-MLflow warnings are rerouted to an MLflow event logger with level\n                 WARNING for the current thread. `False` otherwise.\n        \"\"\"\n        return get_current_thread_id() in self._rerouted_threads\n\n\n_WARNINGS_CONTROLLER = _WarningsController()\n\n\n@contextmanager\ndef set_non_mlflow_warnings_behavior_for_current_thread(disable_warnings, reroute_warnings):\n    \"\"\"\n    Context manager that modifies the behavior of non-MLflow warnings upon entry, according to the\n    specified parameters.\n\n    :param disable_warnings: If `True`, disable  (mutate & discard) non-MLflow warnings. If `False`,\n                             do not disable non-MLflow warnings.\n    :param reroute_warnings: If `True`, reroute non-MLflow warnings to an MLflow event logger with\n                             level WARNING. If `False`, do not reroute non-MLflow warnings.\n    \"\"\"\n    prev_disablement_state = (\n        _WARNINGS_CONTROLLER.get_warnings_disablement_state_for_current_thread()\n    )\n    prev_rerouting_state = _WARNINGS_CONTROLLER.get_warnings_rerouting_state_for_current_thread()\n    try:\n        _WARNINGS_CONTROLLER.set_non_mlflow_warnings_disablement_state_for_current_thread(\n            disabled=disable_warnings\n        )\n        _WARNINGS_CONTROLLER.set_non_mlflow_warnings_rerouting_state_for_current_thread(\n            rerouted=reroute_warnings\n        )\n        yield\n    finally:\n        _WARNINGS_CONTROLLER.set_non_mlflow_warnings_disablement_state_for_current_thread(\n            disabled=prev_disablement_state\n        )\n        _WARNINGS_CONTROLLER.set_non_mlflow_warnings_rerouting_state_for_current_thread(\n            rerouted=prev_rerouting_state\n        )\n\n\n@contextmanager\ndef set_mlflow_events_and_warnings_behavior_globally(\n    disable_event_logs, disable_warnings, reroute_warnings\n):\n    \"\"\"\n    Threadsafe context manager that modifies the behavior of MLflow event logging statements\n    and MLflow warnings upon entry, according to the specified parameters. Modifications are\n    applied globally across all threads and are not reverted until all threads that have made\n    a particular modification have exited the context.\n\n    :param disable_event_logs: If `True`, disable (mute & discard) MLflow event logging statements.\n                               If `False`, do not disable MLflow event logging statements.\n    :param disable_warnings: If `True`, disable  (mutate & discard) MLflow warnings. If `False`,\n                             do not disable MLflow warnings.\n    :param reroute_warnings: If `True`, reroute MLflow warnings to an MLflow event logger with\n                             level WARNING. If `False`, do not reroute MLflow warnings.\n    \"\"\"\n\n    with _SetMLflowEventsAndWarningsBehaviorGlobally(\n        disable_event_logs, disable_warnings, reroute_warnings\n    ):\n        yield\n\n\nclass _SetMLflowEventsAndWarningsBehaviorGlobally:\n    _lock = RLock()\n    _disable_event_logs_count = 0\n    _disable_warnings_count = 0\n    _reroute_warnings_count = 0\n\n    def __init__(self, disable_event_logs, disable_warnings, reroute_warnings):\n        self._disable_event_logs = disable_event_logs\n        self._disable_warnings = disable_warnings\n        self._reroute_warnings = reroute_warnings\n\n    def __enter__(self):\n        try:\n            with _SetMLflowEventsAndWarningsBehaviorGlobally._lock:\n                if self._disable_event_logs:\n                    if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count <= 0:\n                        logging_utils.disable_logging()\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count += 1\n\n                if self._disable_warnings:\n                    if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count <= 0:\n                        _WARNINGS_CONTROLLER.set_mlflow_warnings_disablement_state_globally(\n                            disabled=True\n                        )\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count += 1\n\n                if self._reroute_warnings:\n                    if _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count <= 0:\n                        _WARNINGS_CONTROLLER.set_mlflow_warnings_rerouting_state_globally(\n                            rerouted=True\n                        )\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count += 1\n        except Exception:\n            pass\n\n    def __exit__(self, *args, **kwargs):\n        try:\n            with _SetMLflowEventsAndWarningsBehaviorGlobally._lock:\n                if self._disable_event_logs:\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count -= 1\n                if self._disable_warnings:\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count -= 1\n                if self._reroute_warnings:\n                    _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count -= 1\n\n                if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_event_logs_count <= 0:\n                    logging_utils.enable_logging()\n                if _SetMLflowEventsAndWarningsBehaviorGlobally._disable_warnings_count <= 0:\n                    _WARNINGS_CONTROLLER.set_mlflow_warnings_disablement_state_globally(\n                        disabled=False\n                    )\n                if _SetMLflowEventsAndWarningsBehaviorGlobally._reroute_warnings_count <= 0:\n                    _WARNINGS_CONTROLLER.set_mlflow_warnings_rerouting_state_globally(\n                        rerouted=False\n                    )\n        except Exception:\n            pass\n", "path": "mlflow/utils/autologging_utils/logging_and_warnings.py"}]}