From 448a7bd08d94b89270d0febbcac59f9741af46b2 Mon Sep 17 00:00:00 2001 From: Yuhong Guo Date: Wed, 1 May 2019 01:47:16 +0800 Subject: [PATCH] Add lock in fetch_and_execute_function_to_run of import_thread.py (#4718) --- python/ray/import_thread.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/ray/import_thread.py b/python/ray/import_thread.py index 3de0cb079..440417020 100644 --- a/python/ray/import_thread.py +++ b/python/ray/import_thread.py @@ -124,8 +124,11 @@ class ImportThread(object): return try: - # Deserialize the function. - function = pickle.loads(serialized_function) + # FunctionActorManager may call pickle.loads at the same time. + # Importing the same module in different threads causes deadlock. + with self.worker.function_actor_manager.lock: + # Deserialize the function. + function = pickle.loads(serialized_function) # Run the function. function({"worker": self.worker}) except Exception: