mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-07-07 07:41:28 +08:00
suppress channel notifications for ui background tasks
This commit is contained in:
26
app/core/message_context.py
Normal file
26
app/core/message_context.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import contextvars
|
||||
from contextlib import contextmanager
|
||||
from typing import Iterator
|
||||
|
||||
_suppress_message_channel = contextvars.ContextVar(
|
||||
"suppress_message_channel", default=False
|
||||
)
|
||||
|
||||
|
||||
def is_message_channel_suppressed() -> bool:
|
||||
"""
|
||||
当前上下文是否禁止向外部消息渠道派发通知。
|
||||
"""
|
||||
return bool(_suppress_message_channel.get())
|
||||
|
||||
|
||||
@contextmanager
|
||||
def suppress_message_channel() -> Iterator[None]:
|
||||
"""
|
||||
在当前上下文中临时禁用外部消息渠道派发。
|
||||
"""
|
||||
token = _suppress_message_channel.set(True)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
_suppress_message_channel.reset(token)
|
||||
Reference in New Issue
Block a user