@@ -323,6 +323,7 @@ def _path_in_task(self, executor_task_id, *path_components):
323323 return os .path .join (self ._function_data_dir .name , task_dir , * path_components )
324324
325325 def submit (self , func , resource_specification , * args , ** kwargs ):
326+ import cloudpickle
326327 """Processes the Parsl app by its arguments and submits the function
327328 information to the task queue, to be executed using the TaskVine
328329 system. The args and kwargs are processed for input and output files to
@@ -459,8 +460,15 @@ def submit(self, func, resource_specification, *args, **kwargs):
459460 function_context_args = resource_specification .get ('function_context_args' , [])
460461 function_context_kwargs = resource_specification .get ('function_context_kwargs' , {})
461462 function_context_file = os .path .join (self ._function_data_dir .name , func .__name__ , 'function_context' )
462- self ._serialize_object_to_file (function_context_file , [function_context , function_context_args , function_context_kwargs ])
463+
464+ # DEBUG
465+ with open ('/tmp/tmp.context.executor.function.module.file' , 'w' ) as f :
466+ f .write (str (function_context .__module__ ))
467+
468+ self ._cloudpickle_serialize_object_to_file (function_context_file , [function_context , function_context_args , function_context_kwargs ])
463469 self ._map_func_names_to_func_details [func .__name__ ].update ({'function_context_file' : function_context_file })
470+ # DEBUG
471+ shutil .copyfile (function_context_file , '/tmp/tmp.context.file' )
464472 else :
465473 function_context_file = self ._map_func_names_to_func_details [func .__name__ ]['function_context_file' ]
466474
@@ -472,6 +480,21 @@ def submit(self, func, resource_specification, *args, **kwargs):
472480 self ._serialize_object_to_file (function_file , func )
473481 if exec_mode == 'serverless' :
474482 self ._map_func_names_to_func_details [func .__name__ ]['is_serialized' ] = True
483+
484+ # DEBUG
485+ if exec_mode == 'serverless' :
486+ import copy
487+ kwargs = copy .deepcopy (kwargs )
488+ logger .info (f'ThanhDBG before trimming kwargs: { kwargs } ' )
489+ # pop function context stuff, that should not propagate with the invocation function
490+ if 'function_context' in kwargs ['parsl_resource_specification' ]:
491+ del kwargs ['parsl_resource_specification' ]['function_context' ]
492+ if 'function_context_args' in kwargs ['parsl_resource_specification' ]:
493+ del kwargs ['parsl_resource_specification' ]['function_context_args' ]
494+ if 'function_context_kwargs' in kwargs ['parsl_resource_specification' ]:
495+ del kwargs ['parsl_resource_specification' ]['function_context_kwargs' ]
496+ logger .info (f'ThanhDBG after trimming kwargs: { kwargs } ' )
497+
475498 args_dict = {'args' : args , 'kwargs' : kwargs }
476499 self ._serialize_object_to_file (argument_file , args_dict )
477500
@@ -556,6 +579,12 @@ def _serialize_object_to_file(self, path, obj):
556579 while written < len (serialized_obj ):
557580 written += f_out .write (serialized_obj [written :])
558581
582+ def _cloudpickle_serialize_object_to_file (self , path , obj ):
583+ """Takes any object and serializes it to the file path."""
584+ import cloudpickle
585+ with open (path , 'wb' ) as f :
586+ cloudpickle .dump (obj , f )
587+
559588 def _construct_map_file (self , map_file , input_files , output_files ):
560589 """ Map local filepath of parsl files to the filenames at the execution worker.
561590 If using a shared filesystem, the filepath is mapped to its absolute filename.
0 commit comments