diff --git a/python/ray/remote_function.py b/python/ray/remote_function.py index 4e09e4016b1d..1bd254cf4796 100644 --- a/python/ray/remote_function.py +++ b/python/ray/remote_function.py @@ -14,15 +14,6 @@ DEFAULT_REMOTE_FUNCTION_MAX_CALLS = 0 -def in_ipython(): - """Return true if we are in an IPython interpreter and false otherwise.""" - try: - __IPYTHON__ - return True - except NameError: - return False - - def compute_function_id(function): """Compute an function ID for a function. @@ -36,14 +27,14 @@ def compute_function_id(function): # Include the function module and name in the hash. function_id_hash.update(function.__module__.encode("ascii")) function_id_hash.update(function.__name__.encode("ascii")) - # If we are running a script or are in IPython, include the source code in - # the hash. If we are in a regular Python interpreter we skip this part - # because the source code is not accessible. If the function is a built-in - # (e.g., Cython), the source code is not accessible. - import __main__ as main - if (hasattr(main, "__file__") or in_ipython()) \ - and inspect.isfunction(function): - function_id_hash.update(inspect.getsource(function).encode("ascii")) + try: + # If we are running a script or are in IPython, include the source code + # in the hash. + source = inspect.getsource(function).encode("ascii") + function_id_hash.update(source) + except (IOError, OSError, TypeError): + # Source code may not be available: e.g. Cython or Python interpreter. + pass # Compute the function ID. function_id = function_id_hash.digest() assert len(function_id) == 20