@@ -966,28 +966,41 @@ async def invoke_async(
966966 namespace_name , function_name , function_event ,
967967 function_version , function_async )
968968
969- def use_routine_framework () -> IntegrateDispatch :
969+ def use_routine_dispatcher (
970+ override_handler : bool = True
971+ ) -> IntegrateDispatch :
970972 '''
971973 Use the routine dispatch framework for integrated
972974 invoke for current serverless cloud functions.
973975
974976 Note that this function will immediately add or override
975- the main function at the source of the call.
977+ the main function at the source of the call, unless
978+ the parameter override_handler is set to False.
979+
980+ Args:
981+ override_handler: Whether to create or override the
982+ serverless cloud function main processing function
983+ at the source of this function call.
976984
977985 Returns:
978986 Returns an instance of the integrated invoke dispatcher.
979987
980988 Raises:
989+ ValueError: Parameter values are not as expected.
981990 ModuleNotFoundError: Can't fault the module object from which
982991 the current function call originated.
983992 '''
984993
994+ if override_handler == None or not isinstance (override_handler , bool ):
995+ raise ValueError ('<override_handler> value invalid' )
996+
985997 integrate_dispatch : IntegrateDispatch = IntegrateDispatch ()
986998
987- try :
988- module_name : str = inspect .currentframe ().f_back .f_globals ['__name__' ]
989- setattr (sys .modules [module_name ], 'main' , integrate_dispatch .handler )
990- except KeyError :
991- raise ModuleNotFoundError ('no call source module found' )
999+ if override_handler :
1000+ try :
1001+ module_name : str = inspect .currentframe ().f_back .f_globals ['__name__' ]
1002+ setattr (sys .modules [module_name ], 'main' , integrate_dispatch .handler )
1003+ except KeyError :
1004+ raise ModuleNotFoundError ('no call source module found' )
9921005
9931006 return integrate_dispatch
0 commit comments