瀏覽代碼

move __file__ check below MainProcess check

Falko Schindler 2 年之前
父節點
當前提交
fd9ea4c9e0
共有 1 個文件被更改,包括 5 次插入5 次删除
  1. 5 5
      nicegui/run.py

+ 5 - 5
nicegui/run.py

@@ -4,7 +4,7 @@ import os
 import sys
 import sys
 from typing import List, Optional, Tuple
 from typing import List, Optional, Tuple
 
 
-import __main__ as main
+import __main__
 import uvicorn
 import uvicorn
 from uvicorn.main import STARTUP_FAILURE
 from uvicorn.main import STARTUP_FAILURE
 from uvicorn.supervisors import ChangeReload, Multiprocess
 from uvicorn.supervisors import ChangeReload, Multiprocess
@@ -58,10 +58,6 @@ def run(*,
     :param tailwind: whether to use Tailwind (experimental, default: `True`)
     :param tailwind: whether to use Tailwind (experimental, default: `True`)
     :param kwargs: additional keyword arguments are passed to `uvicorn.run`
     :param kwargs: additional keyword arguments are passed to `uvicorn.run`
     '''
     '''
-    if reload and not hasattr(main, '__file__'):
-        logging.warning('auto-reloading is only supported when running from a file')
-        reload = False
-
     globals.ui_run_has_been_called = True
     globals.ui_run_has_been_called = True
     globals.reload = reload
     globals.reload = reload
     globals.title = title
     globals.title = title
@@ -75,6 +71,10 @@ def run(*,
     if multiprocessing.current_process().name != 'MainProcess':
     if multiprocessing.current_process().name != 'MainProcess':
         return
         return
 
 
+    if reload and not hasattr(__main__, '__file__'):
+        logging.warning('auto-reloading is only supported when running from a file')
+        globals.reload = reload = False
+
     if fullscreen:
     if fullscreen:
         native = True
         native = True
     if window_size:
     if window_size: