unsloth/studio/backend
Velsa 981f477e31
fix: reconfigure stdout to UTF-8 on Windows to prevent UnicodeEncodeError on startup (#4493)
* fix: reconfigure stdout UTF-8 on Windows to prevent UnicodeEncodeError from emoji

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: default frontend_path when None to fix blank page when venv is pre-activated

* Restore Windows UTF-8 stdout fix dropped in earlier commit

The cp1252 console encoding on Windows cannot render emoji characters
used in startup messages (e.g. print(" Frontend loaded ...")).
This causes UnicodeEncodeError and crashes the server before it starts.

Place sys.stdout.reconfigure(encoding="utf-8", errors="replace") at the
top of run_server(), unconditionally before any print() or structlog
call, so all emoji output is covered -- including the frontend status
messages and silent=True paths that the original placement missed.

Guarded by sys.platform == "win32" and hasattr check, so it is a no-op
on Linux/macOS and safe in non-standard stdout environments (Jupyter,
piped IO).

* fix: preserve run_server(None) as headless, fix CLI frontend kwarg

Remove the frontend_path=None fallback in run_server() that changed
None from "headless/API-only" to "mount bundled frontend", breaking
backwards compatibility for embedders.

The blank-page bug was actually caused by the CLI wrappers always
passing frontend_path=frontend (even when frontend=None), which
overrode run_server()'s default. Fix studio.py and ui.py to only
pass frontend_path when the user explicitly sets --frontend.

* fix: use timeout loop for shutdown event in ui command

Match studio_default()'s shutdown loop that uses a 1-second timeout
on Event.wait(). Without a timeout, the bare wait() blocks at the C
level on Linux, preventing Python from delivering SIGINT (Ctrl+C).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <danielhanchen@gmail.com>
2026-03-22 04:49:59 -07:00
..
assets studio: improve onboarding UX, tooltips, and training defaults (#4355) 2026-03-17 07:46:07 -07:00
auth fix: remove old comments (#4292) 2026-03-14 16:50:13 +04:00
core feat(chat): server-side timings, context display & source hover cards (#4467) 2026-03-20 23:42:01 -07:00
loggers Final cleanup 2026-03-12 18:28:04 +00:00
models feat(chat): server-side timings, context display & source hover cards (#4467) 2026-03-20 23:42:01 -07:00
plugins feat(studio): multi-file unstructured seed upload with better backend extraction (#4468) 2026-03-20 13:22:42 -07:00
requirements feat(studio): multi-file unstructured seed upload with better backend extraction (#4468) 2026-03-20 13:22:42 -07:00
routes feat(chat): server-side timings, context display & source hover cards (#4467) 2026-03-20 23:42:01 -07:00
state Final cleanup 2026-03-12 18:28:04 +00:00
tests feat: support GGUF export for non-PEFT models + fix venv_t5 switching for local checkpoints (#4455) 2026-03-20 12:13:18 +04:00
utils feat(chat): server-side timings, context display & source hover cards (#4467) 2026-03-20 23:42:01 -07:00
__init__.py Final cleanup 2026-03-12 18:28:04 +00:00
colab.py Fix Install commands for Windows + 1 line installs (#4447) 2026-03-19 02:09:09 -07:00
main.py studio: web search, KV cache dtype, training progress, inference fixes 2026-03-17 00:30:01 -07:00
run.py fix: reconfigure stdout to UTF-8 on Windows to prevent UnicodeEncodeError on startup (#4493) 2026-03-22 04:49:59 -07:00