From d2d66c576e56174783068fe6fe5fc9780179af41 Mon Sep 17 00:00:00 2001 From: Yu Kobayashi Date: Sat, 16 Feb 2019 12:45:44 +0900 Subject: [PATCH] Support non ascii characters in the source code (#4047) --- python/ray/function_manager.py | 4 +++- test/runtest.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/python/ray/function_manager.py b/python/ray/function_manager.py index df01088aa..e72fe64f1 100644 --- a/python/ray/function_manager.py +++ b/python/ray/function_manager.py @@ -123,7 +123,9 @@ class FunctionDescriptor(object): try: # If we are running a script or are in IPython, include the source # code in the hash. - source = inspect.getsource(function).encode("ascii") + source = inspect.getsource(function) + if sys.version_info[0] >= 3: + source = source.encode() function_source_hasher.update(source) function_source_hash = function_source_hasher.digest() except (IOError, OSError, TypeError): diff --git a/test/runtest.py b/test/runtest.py index de0fe5699..7036e57f6 100644 --- a/test/runtest.py +++ b/test/runtest.py @@ -1,3 +1,4 @@ +# coding: utf-8 from __future__ import absolute_import from __future__ import division from __future__ import print_function @@ -2767,3 +2768,12 @@ def test_raylet_is_robust_to_random_messages(shutdown_only): return 1 assert ray.get(f.remote()) == 1 + + +def test_non_ascii_comment(ray_start): + @ray.remote + def f(): + # 日本語 Japanese comment + return 1 + + assert ray.get(f.remote()) == 1