|
@@ -1,29 +1,36 @@
|
|
|
import threading
|
|
|
from functools import wraps
|
|
|
|
|
|
-from .coroutinebased import CoroutineBasedSession
|
|
|
from .base import AbstractSession
|
|
|
+from .coroutinebased import CoroutineBasedSession
|
|
|
from .threadbased import ThreadBasedSession, DesignatedThreadSession
|
|
|
from ..exceptions import SessionNotFoundException
|
|
|
|
|
|
+THREAD_BASED = 'ThreadBased'
|
|
|
+COROUTINE_BASED = 'CoroutineBased'
|
|
|
+
|
|
|
_session_type = ThreadBasedSession
|
|
|
|
|
|
-__all__ = ['run_async', 'run_asyncio_coroutine', 'register_thread']
|
|
|
+__all__ = ['run_async', 'run_asyncio_coroutine', 'register_thread', 'THREAD_BASED', 'COROUTINE_BASED']
|
|
|
|
|
|
_server_started = False
|
|
|
|
|
|
|
|
|
-def mark_server_started():
|
|
|
+def mark_server_started(session_type_name=None):
|
|
|
"""标记服务端已经启动. 仅用于PyWebIO内部使用"""
|
|
|
global _server_started
|
|
|
_server_started = True
|
|
|
|
|
|
+ if session_type_name is not None:
|
|
|
+ _set_session_implement(session_type_name)
|
|
|
|
|
|
-def set_session_implement(session_type):
|
|
|
+
|
|
|
+def _set_session_implement(session_type_name):
|
|
|
"""设置会话实现类. 仅用于PyWebIO内部使用"""
|
|
|
global _session_type
|
|
|
- assert session_type in [ThreadBasedSession, CoroutineBasedSession, DesignatedThreadSession]
|
|
|
- _session_type = session_type
|
|
|
+ sessions = {THREAD_BASED: ThreadBasedSession, COROUTINE_BASED: CoroutineBasedSession}
|
|
|
+ assert session_type_name in sessions, ValueError('No "%s" Session type ' % session_type_name)
|
|
|
+ _session_type = sessions[session_type_name]
|
|
|
|
|
|
|
|
|
def get_session_implement():
|
|
@@ -32,8 +39,9 @@ def get_session_implement():
|
|
|
|
|
|
|
|
|
def _start_script_mode_server():
|
|
|
+ global _session_type
|
|
|
from ..platform import start_server_in_current_thread_session
|
|
|
- set_session_implement(DesignatedThreadSession)
|
|
|
+ _session_type = DesignatedThreadSession
|
|
|
start_server_in_current_thread_session()
|
|
|
|
|
|
|