Skip to content

Commit 3f8f044

Browse files
committed
python_code: put vars just in locals
1 parent 5a90fb8 commit 3f8f044

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

hooks/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import List, Union
99

1010
from mcdreforged.api.all import *
11+
1112
from ruamel import yaml
1213

1314
from hooks.utils import *
@@ -61,7 +62,6 @@ def __init__(self, name, task_type, created_by, command):
6162

6263
command: str = ''
6364

64-
@new_thread('hooks - execute')
6565
def execute_task(self, server: PluginServerInterface, hook: str, var_dict: dict = None, obj_dict: dict = None):
6666
server.logger.debug(f'Executing task: {self.task_name}, task_type: {self.task_type}, command: {self.command}')
6767
server.logger.debug(f'objects_dict: {str(var_dict)}')
@@ -119,15 +119,15 @@ def execute_task(self, server: PluginServerInterface, hook: str, var_dict: dict
119119
# python code
120120
elif self.task_type == TaskType.python_code:
121121
if obj_dict is not None:
122-
exec(self.command, obj_dict, {})
122+
exec(self.command, {}, obj_dict)
123123
else:
124124
if var_dict is not None:
125-
exec(self.command, var_dict, locals())
125+
exec(self.command, {}, var_dict)
126126
else:
127-
exec(self.command, globals(), locals())
127+
exec(self.command, {}, locals())
128128

129-
server.logger.debug(f'Task finished, name: {self.task_name}, task_type: {self.task_type}, command: {self.command}, '
130-
f'costs {time.time() - start_time} seconds.')
129+
server.logger.debug(f'Task finished, name: {self.task_name}, task_type: {self.task_type}, '
130+
f'command: {self.command}, costs {time.time() - start_time} seconds.')
131131

132132

133133
def stop_all_schedule_daemon_threads():
@@ -142,7 +142,7 @@ def stop_all_schedule_daemon_threads():
142142
class AThread(threading.Thread):
143143
def init_thread(self):
144144
super().__init__(daemon=True)
145-
145+
146146
def set_thread_name(self, name: str):
147147
self.name = name
148148

0 commit comments

Comments
 (0)