|
|
|
@ -368,6 +368,11 @@ def ast_to_func(ast_root, dyfunc, delete_on_exit=True):
|
|
|
|
|
TODO: If only decorate one of inner function instead of decorating the main
|
|
|
|
|
function, the other inner functions are invisible for the decorated function.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def remove_file(filepath):
|
|
|
|
|
if os.path.exists(filepath):
|
|
|
|
|
os.remove(filepath)
|
|
|
|
|
|
|
|
|
|
source = ast_to_source_code(ast_root)
|
|
|
|
|
import_fluid = "import paddle.fluid as fluid\n"
|
|
|
|
|
source = import_fluid + source
|
|
|
|
@ -382,7 +387,9 @@ def ast_to_func(ast_root, dyfunc, delete_on_exit=True):
|
|
|
|
|
f.write(source)
|
|
|
|
|
|
|
|
|
|
if delete_on_exit:
|
|
|
|
|
atexit.register(lambda: os.remove(f.name))
|
|
|
|
|
atexit.register(lambda: remove_file(f.name))
|
|
|
|
|
atexit.register(lambda: remove_file(f.name[:-3] + ".pyc"))
|
|
|
|
|
|
|
|
|
|
module = imp.load_source(module_name, f.name)
|
|
|
|
|
func_name = dyfunc.__name__
|
|
|
|
|
if not hasattr(module, func_name):
|
|
|
|
|