3232def random_object_id ():
3333 return photon .ObjectID ("" .join ([chr (random .randint (0 , 255 )) for _ in range (20 )]))
3434
35+ def random_string ():
36+ return "" .join ([chr (random .randint (0 , 255 )) for _ in range (20 )])
37+
3538class FunctionID (object ):
3639 def __init__ (self , function_id ):
3740 self .function_id = function_id
@@ -516,7 +519,7 @@ def run_function_on_all_workers(self, function):
516519 if self .mode is None :
517520 self .cached_functions_to_run .append (function )
518521 else :
519- function_to_run_id = np . random . randint ( 0 , 1000 )
522+ function_to_run_id = random_string ( )
520523 key = "FunctionsToRun:{}" .format (function_to_run_id )
521524 self .redis_client .hmset (key , {"function_id" : function_to_run_id ,
522525 "function" : pickling .dumps (function )})
@@ -747,7 +750,7 @@ def fetch_and_process_reusable_variable(key, worker=global_worker):
747750 # record the traceback and notify the scheduler of the failure.
748751 traceback_str = format_error_message (traceback .format_exc ())
749752 # Log the error message.
750- error_key = "ReusableVariableImportError:{}" .format ("" . join ([ chr ( random . randint ( 0 , 255 )) for _ in range ( 20 )] ))
753+ error_key = "ReusableVariableImportError:{}" .format (random_string ( ))
751754 worker .redis_client .hmset (error_key , {"name" : reusable_variable_name ,
752755 "message" : traceback_str })
753756 worker .redis_client .rpush ("ErrorKeys" , error_key )
@@ -766,7 +769,7 @@ def fetch_and_process_function_to_run(key, worker=global_worker):
766769 traceback_str = traceback .format_exc ()
767770 # Log the error message.
768771 name = function .__name__ if "function" in locals () and hasattr (function , "__name__" ) else ""
769- error_key = "FunctionToRunError:{}" .format ("" . join ([ chr ( random . randint ( 0 , 255 )) for _ in range ( 20 )] ))
772+ error_key = "FunctionToRunError:{}" .format (random_string ( ))
770773 worker .redis_client .hmset (error_key , {"name" : name ,
771774 "message" : traceback_str })
772775 worker .redis_client .rpush ("ErrorKeys" , error_key )
@@ -832,7 +835,7 @@ def connect(address_info, mode=WORKER_MODE, worker=global_worker):
832835 mode: The mode of the worker. One of SCRIPT_MODE, WORKER_MODE, PYTHON_MODE,
833836 and SILENT_MODE.
834837 """
835- worker .worker_id = np . random . randint ( 0 , 1000000 )
838+ worker .worker_id = random_string ( )
836839 worker .connected = True
837840 worker .set_mode (mode )
838841 # If running Ray in PYTHON_MODE, there is no need to create call create_worker
@@ -1069,7 +1072,7 @@ def process_task(task): # wrapping these lines in a function should cause the lo
10691072 failure_objects = [failure_object for _ in range (len (return_object_ids ))]
10701073 store_outputs_in_objstore (return_object_ids , failure_objects , worker )
10711074 # Log the error message.
1072- error_key = "TaskError:{}" .format ("" . join ([ chr ( random . randint ( 0 , 255 )) for _ in range ( 20 )] ))
1075+ error_key = "TaskError:{}" .format (random_string ( ))
10731076 worker .redis_client .hmset (error_key , {"function_id" : function_id .id (),
10741077 "function_name" : function_name ,
10751078 "message" : traceback_str })
@@ -1082,7 +1085,7 @@ def process_task(task): # wrapping these lines in a function should cause the lo
10821085 # The attempt to reinitialize the reusable variables threw an exception.
10831086 # We record the traceback and notify the scheduler.
10841087 traceback_str = format_error_message (traceback .format_exc ())
1085- error_key = "ReusableVariableReinitializeError:{}" .format ("" . join ([ chr ( random . randint ( 0 , 255 )) for _ in range ( 20 )] ))
1088+ error_key = "ReusableVariableReinitializeError:{}" .format (random_string ( ))
10861089 worker .redis_client .hmset (error_key , {"task_instance_id" : "NOTIMPLEMENTED" ,
10871090 "task_id" : "NOTIMPLEMENTED" ,
10881091 "function_id" : function_id .id (),
0 commit comments