MCPcopy Index your code
hub / github.com/Tencent/CodeAnalysis / start

Method start

client/node/common/task.py:151–196  ·  view source on GitHub ↗

start to run the task :param running_tasks: running task list :param lock_source_dir: lock to manipulate source dir

(self)

Source from the content-addressed store, hash-verified

149 return self._done
150
151 def start(self):
152 """start to run the task
153
154 :param running_tasks: running task list
155 :param lock_source_dir: lock to manipulate source dir
156 """
157 try:
158 with open(self.request_file, 'r', encoding='utf-8') as rf:
159 task_request = json.load(rf)
160 task_display_name = ToolDisplay.get_tool_display_name(task_request)
161
162 if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
163 # LogPrinter.info('running in a PyInstaller bundle')
164 puppy_task_name = "scantask"
165 if settings.PLATFORMS[sys.platform] == 'windows':
166 puppy_task_name = '%s.exe' % puppy_task_name
167
168 puppy_task_path = os.path.join(settings.BASE_DIR, puppy_task_name)
169 # 以可执行程序的方式调用
170 cmd_args = [puppy_task_path, self.request_file, self.response_file]
171 else:
172 python_cmd = "python3" # python3命令
173 # LogPrinter.info('running in python code')
174 if not PythonTool.is_local_python_command_available(python_cmd, python_version="3"):
175 raise ConfigError("python3 command is not available, please install Python3.")
176
177 cmd_args = [python_cmd, 'task/puppytask.py', self.request_file, self.response_file]
178
179 LogPrinter.info(f'Task_{task_request["id"]} ({task_display_name}) starts ...')
180
181 # 命令行参数加上引号,避免路径包含空格触发命令异常
182 cmd_args = PathMgr().format_cmd_arg_list(cmd_args)
183
184 self._task_proc = SubProcController(cmd_args,
185 stdout_filepath=self.task_log,
186 stderr_filepath=self.task_log,
187 env=EnvSet().get_origin_env(self.env))
188
189 self._task_expired_time = time.time() + app.settings.TASK_EXPIRED.total_seconds()
190
191 except Exception as err:
192 logger.exception('encounter error when starting task process')
193 self.code = errcode.E_NODE_TASK
194 self.msg = u"%s: %s" % (type(err).__name__, err)
195 self.data = traceback.format_exc()
196 self._done = True

Callers 12

runMethod · 0.95
runMethod · 0.95
runMethod · 0.95
load_source_dirMethod · 0.45
_common_handleMethod · 0.45
__common_path_filterMethod · 0.45
_lint_blameMethod · 0.45
_duplicate_blameMethod · 0.45
_ccn_blameMethod · 0.45
start_threadMethod · 0.45
startClientMethod · 0.45
index.tsFile · 0.45

Calls 8

ConfigErrorClass · 0.90
EnvSetClass · 0.90
get_tool_display_nameMethod · 0.80
get_origin_envMethod · 0.80
exceptionMethod · 0.80
loadMethod · 0.45
infoMethod · 0.45

Tested by 1

runMethod · 0.76