Move function/actor exporting & loading code to function_manager.py (#3003)

Move function/actor exporting & loading code to function_manager.py to prepare the code change for function descriptor for python.
This commit is contained in:
Yuhong Guo
2018-10-04 07:21:04 +08:00
committed by Robert Nishihara
parent d73ee36e60
commit 9948e8c11b
6 changed files with 559 additions and 502 deletions
+18
View File
@@ -5,6 +5,7 @@ from __future__ import print_function
import binascii
import functools
import hashlib
import inspect
import numpy as np
import os
import subprocess
@@ -144,6 +145,23 @@ def is_cython(obj):
(hasattr(obj, "__func__") and check_cython(obj.__func__))
def is_function_or_method(obj):
"""Check if an object is a function or method.
Args:
obj: The Python object in question.
Returns:
True if the object is an function or method.
"""
return (inspect.isfunction(obj) or inspect.ismethod(obj) or is_cython(obj))
def is_class_method(f):
"""Returns whether the given method is a class_method."""
return hasattr(f, "__self__") and f.__self__ is not None
def random_string():
"""Generate a random string to use as an ID.