Skip to content

Commit

Permalink
refactor(event): 事件处理调整为深复制,避免多线程环境下数据异常
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityPacer committed Jul 29, 2024
1 parent da2c755 commit 2b8c313
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/command.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import importlib
import threading
import traceback
Expand All @@ -11,8 +12,7 @@
from app.chain.system import SystemChain
from app.chain.transfer import TransferChain
from app.core.config import settings
from app.core.event import Event as ManagerEvent
from app.core.event import eventmanager, EventManager
from app.core.event import Event as ManagerEvent, eventmanager, EventManager
from app.core.plugin import PluginManager
from app.helper.message import MessageHelper
from app.helper.thread import ThreadHelper
Expand Down Expand Up @@ -194,7 +194,7 @@ def __run(self):
# 插件事件
self.threader.submit(
self.pluginmanager.run_plugin_method,
class_name, method_name, event
class_name, method_name, copy.deepcopy(event)
)

else:
Expand All @@ -217,7 +217,7 @@ def __run(self):
if hasattr(class_obj, method_name):
self.threader.submit(
getattr(class_obj, method_name),
event
copy.deepcopy(event)
)
except Exception as e:
logger.error(f"事件处理出错:{str(e)} - {traceback.format_exc()}")
Expand Down

0 comments on commit 2b8c313

Please sign in to comment.