Skip to content

Commit

Permalink
sys.stdout and sys.stderr are unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 committed Feb 24, 2024
1 parent 6cf374d commit f63ecc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Libraries/Utility/src/utility/error_handling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import inspect
import os
import sys
import traceback
import types
Expand Down Expand Up @@ -293,6 +294,8 @@ def wrapper(*args, **kwargs) -> RT | None:
full_message: str = "\n".join(detailed_message)

if action == "stderr":
if sys.stderr is None:
sys.stderr = open(os.devnull, "w") # noqa: PTH123, SIM115, PLW1514 # pylint: disable=all
print(full_message, sys.stderr) # noqa: T201
elif action == "print":
print(full_message) # noqa: T201
Expand Down
6 changes: 3 additions & 3 deletions Tools/HoloPatcher/src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,14 @@ def handle_exit_button(self):
i = 0
while self.task_thread.is_alive():
try:
self.task_thread._stop() # type: ignore[attr-defined]
print("force terminate of install thread succeeded", sys.stdout) # noqa: T201
self.task_thread._stop() # type: ignore[attr-defined] # pylint: disable=protected-access
print("force terminate of install thread succeeded")
except BaseException as e: # pylint: disable=W0718 # noqa: BLE001
self._handle_general_exception(e, "Error using self.install_thread._stop()", msgbox=False)
try:
if self.task_thread.ident is None:
msg = "task ident is None, expected an int."
raise ValueError(msg)
raise ValueError(msg) # noqa: TRY301
self.async_raise(self.task_thread.ident, SystemExit)
except BaseException as e: # pylint: disable=W0718 # noqa: BLE001
self._handle_general_exception(e, "Error using async_raise(self.install_thread.ident, SystemExit)", msgbox=False)
Expand Down

0 comments on commit f63ecc0

Please sign in to comment.