File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 1+ import os
12import pickle
3+ from contextlib import contextmanager
24from pathlib import Path
35from typing import Any , Union
46
57from lightning_utilities import module_available
68from lightning_utilities .core .imports import RequirementCache
79
10+
11+ @contextmanager
12+ def _suppress_os_stderr ():
13+ devnull_fd = os .open (os .devnull , os .O_WRONLY )
14+ old_stderr_fd = os .dup (2 )
15+ os .dup2 (devnull_fd , 2 ) # redirect stderr (fd 2) to /dev/null
16+ os .close (devnull_fd )
17+ try :
18+ yield
19+ finally :
20+ os .dup2 (old_stderr_fd , 2 ) # restore stderr
21+ os .close (old_stderr_fd )
22+
23+
824_JOBLIB_AVAILABLE = module_available ("joblib" )
925_PYTORCH_AVAILABLE = module_available ("torch" )
10- _TENSORFLOW_AVAILABLE = module_available ("tensorflow" )
11- _KERAS_AVAILABLE = RequirementCache ("tensorflow >=2.0.0" )
26+ with _suppress_os_stderr ():
27+ _TENSORFLOW_AVAILABLE = module_available ("tensorflow" )
28+ _KERAS_AVAILABLE = RequirementCache ("tensorflow >=2.0.0" )
1229
1330if _JOBLIB_AVAILABLE :
1431 import joblib
You can’t perform that action at this time.
0 commit comments