@@ -1076,18 +1076,8 @@ def update(res):
10761076 def handle_error (error ):
10771077 print (f"Error: { error } " , flush = True )
10781078
1079- # Handle memory monitoring by modifying the input arguments instead of using a wrapper
1080- if monitor_memory :
1081- # Modify the input arguments to include monitor_memory flag
1082- modified_inputList = []
1083- for i in inputList :
1084- if isinstance (i , (list , tuple )):
1085- # Convert to list and add monitor_memory as keyword argument
1086- # We'll handle this in the function call by unpacking properly
1087- modified_inputList .append (list (i ) + [monitor_memory ])
1088- else :
1089- modified_inputList .append ((i , monitor_memory ))
1090- inputList = modified_inputList
1079+ # Note: monitor_memory is now handled by the individual functions themselves
1080+ # No need to modify inputList here since functions receive monitor_memory as a parameter
10911081
10921082 actual_function = function
10931083
@@ -1096,43 +1086,20 @@ def handle_error(error):
10961086 # setup results and split over cpus
10971087 results = []
10981088 for i in inputList :
1099- if isinstance (i , list ):
1100- if monitor_memory and len (i ) >= 4 :
1101- # Handle the case where monitor_memory was added as the 4th argument
1102- # Call function with monitor_memory as keyword argument
1103- args = i [:- 1 ] # All arguments except the last one (monitor_memory)
1104- kwargs = {"monitor_memory" : i [- 1 ]}
1105- p .apply_async (
1106- actual_function ,
1107- args = args ,
1108- kwds = kwargs ,
1109- callback = update ,
1110- error_callback = handle_error ,
1111- )
1112- else :
1113- p .apply_async (
1114- actual_function ,
1115- args = i ,
1116- callback = update ,
1117- error_callback = handle_error ,
1118- )
1089+ if isinstance (i , (list , tuple )):
1090+ p .apply_async (
1091+ actual_function ,
1092+ args = i ,
1093+ callback = update ,
1094+ error_callback = handle_error ,
1095+ )
11191096 else :
1120- if monitor_memory and isinstance (i , tuple ) and len (i ) == 2 :
1121- # Handle the case where monitor_memory was added as the 2nd argument
1122- p .apply_async (
1123- actual_function ,
1124- args = (i [0 ],),
1125- kwds = {"monitor_memory" : i [1 ]},
1126- callback = update ,
1127- error_callback = handle_error ,
1128- )
1129- else :
1130- p .apply_async (
1131- actual_function ,
1132- args = (i ,),
1133- callback = update ,
1134- error_callback = handle_error ,
1135- )
1097+ p .apply_async (
1098+ actual_function ,
1099+ args = (i ,),
1100+ callback = update ,
1101+ error_callback = handle_error ,
1102+ )
11361103 p .close ()
11371104 p .join ()
11381105 return results
0 commit comments