Update main.py
This commit is contained in:
1 parent
0c5a050786
commit
8aafb6dc89
1 file changed
+24
-4
@@ -1,5 +1,18 @@
|
|||||||
import platform as _platform
|
import platform as _platform
|
||||||
import subprocess as _subprocess
|
import subprocess as _subprocess
|
||||||
|
import sys as _sys
|
||||||
|
|
||||||
|
# ── Make stdout/stderr UTF-8 tolerant ────────────────────────────────────────
|
||||||
|
# On non-UTF-8 Windows consoles (cp1254/cp1252/cp936...) any print() containing
|
||||||
|
# an emoji raises UnicodeEncodeError. Several of those prints sit inside except
|
||||||
|
# handlers, so the handler itself would blow up and skip the recovery code that
|
||||||
|
# follows it — turning a recoverable error into a silent hang. errors="replace"
|
||||||
|
# makes every print safe.
|
||||||
|
for _stream in (_sys.stdout, _sys.stderr):
|
||||||
|
try:
|
||||||
|
_stream.reconfigure(encoding="utf-8", errors="replace")
|
||||||
|
except Exception:
|
||||||
|
pass # frozen builds may have no real stream attached
|
||||||
|
|
||||||
# ── Nuclear: force CREATE_NO_WINDOW on EVERY subprocess call on Windows ───────
|
# ── Nuclear: force CREATE_NO_WINDOW on EVERY subprocess call on Windows ───────
|
||||||
# This patches Popen itself, so no per-file flag is needed anywhere.
|
# This patches Popen itself, so no per-file flag is needed anywhere.
|
||||||
@@ -1231,14 +1244,18 @@ class JarvisLive:
|
|||||||
await asyncio.sleep(1.0)
|
await asyncio.sleep(1.0)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
news_text = await asyncio.wait_for(news_done, timeout=4.0)
|
news_text = await asyncio.wait_for(news_done, timeout=8.0)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
self.ui.write_log(f"SYS: News fetch timed out/failed: {e!r}")
|
||||||
news_text = ""
|
news_text = ""
|
||||||
|
|
||||||
if not self.session:
|
if not self.session:
|
||||||
return
|
return
|
||||||
|
|
||||||
if news_text and len(news_text) > 60:
|
failed = (not news_text) or news_text.startswith(
|
||||||
|
("No news found", "Search failed", "Please provide")
|
||||||
|
)
|
||||||
|
if not failed:
|
||||||
# Show on UI content panel immediately
|
# Show on UI content panel immediately
|
||||||
self.ui.show_content("NEWS — top world news today", news_text)
|
self.ui.show_content("NEWS — top world news today", news_text)
|
||||||
|
|
||||||
@@ -1248,6 +1265,9 @@ class JarvisLive:
|
|||||||
f"is displayed on screen. Do not call any tools.{lang_str}"
|
f"is displayed on screen. Do not call any tools.{lang_str}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
self.ui.write_log(
|
||||||
|
f"SYS: News unavailable — backend returned: {news_text[:120]!r}"
|
||||||
|
)
|
||||||
p2 = (
|
p2 = (
|
||||||
"News headlines could not be fetched right now. "
|
"News headlines could not be fetched right now. "
|
||||||
f"Let the user know briefly.{lang_str}"
|
f"Let the user know briefly.{lang_str}"
|
||||||
@@ -1603,4 +1623,4 @@ def main():
|
|||||||
ui.root.mainloop()
|
ui.root.mainloop()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in new issue
Block a user