Skip to content

Commit efd1916

Browse files
authored
Merge pull request #621 from ryansb/suggestion/uvicorn-inline
Suggestion: don't import uvicorn to allow for alternative asgi servers
2 parents c21a93f + a19f275 commit efd1916

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

fasthtml/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'reg_re_param', 'MiddlewareBase', 'FtResponse', 'unqid', 'setup_ws']
1212

1313
# %% ../nbs/api/00_core.ipynb
14-
import json,uuid,inspect,types,uvicorn,signal,asyncio,threading,inspect
14+
import json,uuid,inspect,types,signal,asyncio,threading,inspect
1515

1616
from fastcore.utils import *
1717
from fastcore.xml import *
@@ -644,6 +644,7 @@ def serve(
644644
if not appname:
645645
if glb.get('__name__')=='__main__': appname = Path(glb.get('__file__', '')).stem
646646
elif code.co_name=='main' and bk.f_back.f_globals.get('__name__')=='__main__': appname = inspect.getmodule(bk).__name__
647+
import uvicorn
647648
if appname:
648649
if not port: port=int(os.getenv("PORT", default=5001))
649650
print(f'Link: http://{"localhost" if host=="0.0.0.0" else host}:{port}')

nbs/api/00_core.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"outputs": [],
4444
"source": [
4545
"#| export\n",
46-
"import json,uuid,inspect,types,uvicorn,signal,asyncio,threading,inspect\n",
46+
"import json,uuid,inspect,types,signal,asyncio,threading,inspect\n",
4747
"\n",
4848
"from fastcore.utils import *\n",
4949
"from fastcore.xml import *\n",
@@ -1630,6 +1630,7 @@
16301630
" if not appname:\n",
16311631
" if glb.get('__name__')=='__main__': appname = Path(glb.get('__file__', '')).stem\n",
16321632
" elif code.co_name=='main' and bk.f_back.f_globals.get('__name__')=='__main__': appname = inspect.getmodule(bk).__name__\n",
1633+
" import uvicorn\n",
16331634
" if appname:\n",
16341635
" if not port: port=int(os.getenv(\"PORT\", default=5001))\n",
16351636
" print(f'Link: http://{\"localhost\" if host==\"0.0.0.0\" else host}:{port}')\n",

0 commit comments

Comments
 (0)