Skip to content

Commit c4dd2a8

Browse files
committed
Removed duplicate call to sys.stdout.fileno() in setup_logging.setup_logging().
Probably best practice to call it just once rather than calling it first to check if it raises an error then again later to actually use the value it returns.
1 parent 2e38107 commit c4dd2a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

labscript_utils/setup_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ def setup_logging(program_name, log_level=logging.DEBUG, terminal_level=logging.
5757
try:
5858
# Check that sys.stdout.fileno is callable, which is needed below. It is NOT
5959
# callable in Jupyter notebooks.
60-
sys.stdout.fileno()
60+
stdout_fileno = sys.stdout.fileno()
6161
except UnsupportedOperation:
6262
# In this case the code is likely being run from a Jupyter notebook, warn the
6363
# user that log messages won't be printed to stdout or stderr.
6464
warnings.warn(
6565
"Logging to stdout and stderr is disabled. See the log files for log messages."
6666
)
6767
else:
68-
if sys.stdout is not None and sys.stdout.fileno() >= 0:
68+
if sys.stdout is not None and stdout_fileno >= 0:
6969
stdout_handler = logging.StreamHandler(sys.stdout)
7070
stdout_handler.setFormatter(formatter)
7171
stdout_handler.setLevel(terminal_level)

0 commit comments

Comments
 (0)