mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[BE]: Enable Ruff + Flake8 G201,G202 logging format rule. (#114474)
Standardizes logging calls to always use logging.exception instead of logging.error where appropriate and enforces it with a lint. Pull Request resolved: https://github.com/pytorch/pytorch/pull/114474 Approved by: https://github.com/jansel, https://github.com/malfet
This commit is contained in:
committed by
PyTorch MergeBot
parent
3a4dea99df
commit
4bb3a02d02
2
.flake8
2
.flake8
@ -18,7 +18,7 @@ ignore =
|
|||||||
# these ignores are from flake8-comprehensions; please fix!
|
# these ignores are from flake8-comprehensions; please fix!
|
||||||
C407,
|
C407,
|
||||||
# these ignores are from flake8-logging-format; please fix!
|
# these ignores are from flake8-logging-format; please fix!
|
||||||
G100,G101,G200,G201,G202
|
G100,G101,G200
|
||||||
# these ignores are from flake8-simplify. please fix or ignore with commented reason
|
# these ignores are from flake8-simplify. please fix or ignore with commented reason
|
||||||
SIM105,SIM108,SIM110,SIM111,SIM113,SIM114,SIM115,SIM116,SIM117,SIM118,SIM119,SIM12,
|
SIM105,SIM108,SIM110,SIM111,SIM113,SIM114,SIM115,SIM116,SIM117,SIM118,SIM119,SIM12,
|
||||||
# flake8-simplify code styles
|
# flake8-simplify code styles
|
||||||
|
@ -43,7 +43,7 @@ ignore = [
|
|||||||
"F821",
|
"F821",
|
||||||
"F841",
|
"F841",
|
||||||
# these ignores are from flake8-logging-format; please fix!
|
# these ignores are from flake8-logging-format; please fix!
|
||||||
"G101", "G201", "G202",
|
"G101",
|
||||||
# these ignores are from RUFF perf; please fix!
|
# these ignores are from RUFF perf; please fix!
|
||||||
"PERF203", "PERF4",
|
"PERF203", "PERF4",
|
||||||
# these ignores are from PYI; please fix!
|
# these ignores are from PYI; please fix!
|
||||||
|
@ -1315,9 +1315,8 @@ def get_guard_fail_reason(
|
|||||||
GuardFail(reason_str or "unknown reason", orig_code_map[code])
|
GuardFail(reason_str or "unknown reason", orig_code_map[code])
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(
|
log.exception(
|
||||||
"Failure in guard_fail_fn callback - raising here will cause a NULL Error on guard eval",
|
"Failure in guard_fail_fn callback - raising here will cause a NULL Error on guard eval",
|
||||||
exc_info=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return reason_str
|
return reason_str
|
||||||
|
@ -400,7 +400,7 @@ def write_record_to_file(filename, exec_record):
|
|||||||
with open(filename, "wb") as f:
|
with open(filename, "wb") as f:
|
||||||
exec_record.dump(f)
|
exec_record.dump(f)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("Unable to write execution record %s", filename, exc_info=True)
|
log.exception("Unable to write execution record %s", filename)
|
||||||
|
|
||||||
|
|
||||||
def count_calls(g: fx.Graph):
|
def count_calls(g: fx.Graph):
|
||||||
|
@ -477,14 +477,13 @@ class MultiprocessContext(PContext):
|
|||||||
failed_proc = self._pc.processes[failed_local_rank]
|
failed_proc = self._pc.processes[failed_local_rank]
|
||||||
error_filepath = self.error_files[failed_local_rank]
|
error_filepath = self.error_files[failed_local_rank]
|
||||||
|
|
||||||
log.error(
|
log.exception(
|
||||||
"failed (exitcode: %s)"
|
"failed (exitcode: %s)"
|
||||||
" local_rank: %s (pid: %s)"
|
" local_rank: %s (pid: %s)"
|
||||||
" of fn: %s (start_method: %s)",
|
" of fn: %s (start_method: %s)",
|
||||||
failed_proc.exitcode,
|
failed_proc.exitcode,
|
||||||
failed_local_rank, e.pid,
|
failed_local_rank, e.pid,
|
||||||
fn_name, self.start_method,
|
fn_name, self.start_method,
|
||||||
exc_info=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
@ -169,11 +169,10 @@ class TimerServer(abc.ABC):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return self._reap_worker(worker_id)
|
return self._reap_worker(worker_id)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
log.error(
|
log.exception(
|
||||||
"Uncaught exception thrown from _reap_worker(), "
|
"Uncaught exception thrown from _reap_worker(), "
|
||||||
"check that the implementation correctly catches exceptions",
|
"check that the implementation correctly catches exceptions",
|
||||||
exc_info=e,
|
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -181,8 +180,8 @@ class TimerServer(abc.ABC):
|
|||||||
while not self._stop_signaled:
|
while not self._stop_signaled:
|
||||||
try:
|
try:
|
||||||
self._run_watchdog()
|
self._run_watchdog()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
log.error("Error running watchdog", exc_info=e)
|
log.exception("Error running watchdog")
|
||||||
|
|
||||||
def _run_watchdog(self):
|
def _run_watchdog(self):
|
||||||
batch_size = max(1, self._request_queue.size())
|
batch_size = max(1, self._request_queue.size())
|
||||||
|
@ -225,8 +225,8 @@ class FileTimerServer:
|
|||||||
self._run_watchdog(fd)
|
self._run_watchdog(fd)
|
||||||
if run_once:
|
if run_once:
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception:
|
||||||
log.error("Error running watchdog", exc_info=e)
|
log.exception("Error running watchdog")
|
||||||
|
|
||||||
def _run_watchdog(self, fd: io.TextIOWrapper) -> None:
|
def _run_watchdog(self, fd: io.TextIOWrapper) -> None:
|
||||||
timer_requests = self._get_requests(fd, self._max_interval)
|
timer_requests = self._get_requests(fd, self._max_interval)
|
||||||
@ -328,6 +328,6 @@ class FileTimerServer:
|
|||||||
except ProcessLookupError:
|
except ProcessLookupError:
|
||||||
log.info("Process with pid=%s does not exist. Skipping", worker_pid)
|
log.info("Process with pid=%s does not exist. Skipping", worker_pid)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception:
|
||||||
log.error("Error terminating pid=%s", worker_pid, exc_info=e)
|
log.exception("Error terminating pid=%s", worker_pid)
|
||||||
return False
|
return False
|
||||||
|
@ -120,6 +120,6 @@ class LocalTimerServer(TimerServer):
|
|||||||
except ProcessLookupError:
|
except ProcessLookupError:
|
||||||
log.info("Process with pid=%s does not exist. Skipping", worker_id)
|
log.info("Process with pid=%s does not exist. Skipping", worker_id)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception:
|
||||||
log.error("Error terminating pid=%s", worker_id, exc_info=e)
|
log.exception("Error terminating pid=%s", worker_id)
|
||||||
return False
|
return False
|
||||||
|
Reference in New Issue
Block a user