Studio: don't apply nest_asyncio on plain CLI starts (breaks asyncio on Python 3.14+) (#7186)
* Studio: don't apply nest_asyncio on plain CLI starts (breaks asyncio on Python 3.14+) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Skip nest_asyncio on Python 3.14+ so notebook and embedded Studio starts also work * Tighten the nest_asyncio gate comment --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: danielhanchen <unslothshared@gmail.com>
This commit is contained in:
parent
8ff2f8e70c
commit
bf4185a2d3
1 changed files with 15 additions and 3 deletions
|
|
@ -1354,11 +1354,23 @@ def run_server(
|
|||
if secure:
|
||||
os.environ["UNSLOTH_SECURE"] = "1"
|
||||
|
||||
import nest_asyncio
|
||||
|
||||
nest_asyncio.apply()
|
||||
|
||||
import asyncio
|
||||
|
||||
# nest_asyncio is for Colab/IPython, where the main thread already runs a loop
|
||||
# the blocking waits below would collide with. Apply it only with a loop running
|
||||
# (a plain CLI start has nothing to nest) and only on Python <= 3.13: on 3.14+
|
||||
# its global Task patch leaves asyncio.current_task() None (tracking moved into
|
||||
# C), which also breaks the background uvicorn loop and 500s every request. It
|
||||
# is archived upstream, so no 3.14 fix is coming; skip it there.
|
||||
if sys.version_info < (3, 14):
|
||||
try:
|
||||
asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
pass
|
||||
else:
|
||||
import nest_asyncio
|
||||
nest_asyncio.apply()
|
||||
|
||||
from threading import Thread, Event
|
||||
import uvicorn
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue