MCPcopy Create free account
hub / github.com/MemTensor/MemOS / submit

Method submit

src/memos/context/context.py:249–277  ·  view source on GitHub ↗

Submit a callable to be executed with the given arguments. Automatically propagates the current thread's context to the worker thread.

(self, fn: Callable[..., T], *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

247 """
248
249 def submit(self, fn: Callable[..., T], *args: Any, **kwargs: Any) -> Any:
250 """
251 Submit a callable to be executed with the given arguments.
252 Automatically propagates the current thread's context to the worker thread.
253 """
254 main_trace_id = get_current_trace_id()
255 main_api_path = get_current_api_path()
256 main_env = get_current_env()
257 main_user_type = get_current_user_type()
258 main_user_name = get_current_user_name()
259 main_context = get_current_context()
260
261 @functools.wraps(fn)
262 def wrapper(*args: Any, **kwargs: Any) -> Any:
263 if main_context:
264 # Create and set new context in worker thread
265 child_context = RequestContext(
266 trace_id=main_trace_id,
267 api_path=main_api_path,
268 env=main_env,
269 user_type=main_user_type,
270 user_name=main_user_name,
271 )
272 child_context._data = main_context._data.copy()
273 set_request_context(child_context)
274
275 return fn(*args, **kwargs)
276
277 return super().submit(wrapper, *args, **kwargs)
278
279 def map(
280 self,

Callers 15

emitMethod · 0.80
execute_taskMethod · 0.80
batch_handlerMethod · 0.80
batch_handlerMethod · 0.80
batch_handlerMethod · 0.80
run_with_thread_poolMethod · 0.80
searchMethod · 0.80
addMethod · 0.80
get_sub_answersMethod · 0.80
_search_with_engineMethod · 0.80
add_graph_edgesMethod · 0.80

Calls 6

get_current_trace_idFunction · 0.85
get_current_api_pathFunction · 0.85
get_current_envFunction · 0.85
get_current_user_typeFunction · 0.85
get_current_user_nameFunction · 0.85
get_current_contextFunction · 0.85

Tested by 1