asgiref异步同步解释 #https://github.com/django/asgiref/blob/master/asgiref/sync.py 类异步同步: """ 实用程序类,该类打开仅在具有 将事件循环转换为在子线程中工作的同步可调用事件。 如果调用堆栈包含异步循环,则代码将在那里运行。 否则,代码将在新线程中的新循环中运行。 ###############不明白#################### 无论哪种方式,该线程都会暂停并等待运行任何线程 在调用之前,使用SyncToAsync从调用堆栈的下一层调用代码 一旦异步任务返回,最后退出。 """
谁能帮我解释一下黑体字?提前谢谢asgiref异步同步解释 #https://github.com/django/asgiref/blob/master/asgiref/sync.py 类异步同步: """ 实用程序类,该类打开仅在具有 将事件循环转换为在子线程中工作的同步可调用事件。 如果调用堆栈包含异步循环,则代码将在那里运行。 否则,代码将在新线程中的新循环中运行。 ###############不明白#################### 无论哪种方式,该线程都会暂停并等待运行任何线程 在调用之前,使用SyncToAsync从调用堆栈的下一层调用代码 一旦异步任务返回,最后退出。 """,django,python-asyncio,django-channels,Django,Python Asyncio,Django Channels,谁能帮我解释一下黑体字?提前谢谢 # https://github.com/django/asgiref/blob/master/asgiref/sync.py class AsyncToSync: """ Utility class which turns an awaitable that only works on the thread with the event loop into a synchronous callable that works in a s
# https://github.com/django/asgiref/blob/master/asgiref/sync.py
class AsyncToSync:
"""
Utility class which turns an awaitable that only works on the thread with
the event loop into a synchronous callable that works in a subthread.
If the call stack contains an async loop, the code runs there.
Otherwise, the code runs in a new loop in a new thread.
############### DON'T UNDERSTAND ####################
Either way, this thread then pauses and waits to run any thread_sensitive
code called from further down the call stack using SyncToAsync, before
finally exiting once the async task returns.
"""