antban commented on code in PR #53016:
URL: https://github.com/apache/spark/pull/53016#discussion_r2533379438
##########
python/pyspark/util.py:
##########
@@ -917,6 +918,59 @@ def default_api_mode() -> str:
return "classic"
+class _FaultHandlerIntegration:
+ def __init__(self) -> None:
+ self._log_path: Optional[str] = None
+ self._log_file: Optional[TextIO] = None
+ self._periodic_dump = False
+
+ def start(self) -> None:
+ self._log_path = os.environ.get("PYTHON_FAULTHANDLER_DIR", None)
+ tracebackDumpIntervalSeconds = os.environ.get(
+ "PYTHON_TRACEBACK_DUMP_INTERVAL_SECONDS", None
+ )
+ if self._log_path:
+ self._log_path = os.path.join(self._log_path, str(os.getpid()))
+ self._log_file = open(self._log_path, "w")
+
+ faulthandler.enable(file=self._log_file)
+
+ if tracebackDumpIntervalSeconds is not None and
int(tracebackDumpIntervalSeconds) > 0:
+ self._periodic_dump = True
+
faulthandler.dump_traceback_later(int(tracebackDumpIntervalSeconds),
repeat=True)
+
+ def stop(self) -> None:
+ if self._periodic_dump:
+ faulthandler.cancel_dump_traceback_later()
+ self._periodic_dump = False
+ if self._log_path:
+ faulthandler.disable()
+ if self._log_file:
+ self._log_file.close()
+ self._log_file = None
+ os.remove(self._log_path)
+ self._log_path = None
+
+
+def with_fault_handler(func: Callable) -> Callable:
+ """
+ Registers fault handler for the duration of function execution.
+ After function execution is over the faulthandler registration is cleaned
as well,
+ including any files created for the integration. Not reentrant.
+ """
+
+ @functools.wraps(func)
+ def wrapper(*args: Any, **kwargs: Any) -> Any:
+ fault_handler = _FaultHandlerIntegration()
Review Comment:
faulthandler as a single word - agree,
move decorator to class + make it a singleton - agree
_FaulthandlerIntegration -> _FaulthandlerHelper - I have no preference, the
names are more or less equal, will rename.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]