Skip to content

Commit 2f9f66e

Browse files
bug fixes and code improvements
1 parent 88d55fd commit 2f9f66e

8 files changed

Lines changed: 44 additions & 35 deletions

File tree

microservices/binary_executor_image/binary_execution.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from concurrent.futures import ThreadPoolExecutor
33
from utils import Database, Data, Metadata, ObjectStorage
44
from constants import Constants
5+
import traceback
56

67

78
class Parameters:
@@ -127,15 +128,10 @@ def create(self,
127128
self.class_method,
128129
self.executor_service_type)
129130

130-
'''self.__thread_pool.submit(self.__pipeline,
131+
self.__thread_pool.submit(self.__pipeline,
131132
module_path,
132133
method_parameters,
133-
description)'''
134-
135-
self.__pipeline(
136-
module_path,
137-
method_parameters,
138-
description)
134+
description)
139135

140136
def update(self,
141137
module_path: str,
@@ -165,7 +161,6 @@ def __pipeline(self,
165161
flag=True)
166162

167163
except Exception as exception:
168-
import traceback
169164
traceback.print_exc()
170165
self.__metadata_creator.create_execution_document(
171166
self.executor_name,
@@ -181,7 +176,6 @@ def __pipeline(self,
181176

182177
def __execute_a_object_method(self, class_instance: object, method: str,
183178
parameters: dict) -> object:
184-
print(type(class_instance), flush=True)
185179
class_method = getattr(class_instance, method)
186180

187181
treated_parameters = self.__parameters_handler.treat(parameters)
@@ -190,7 +184,6 @@ def __execute_a_object_method(self, class_instance: object, method: str,
190184
if self.executor_service_type == Constants.TRAIN_TENSORFLOW_TYPE or \
191185
self.executor_service_type == Constants.TRAIN_SCIKITLEARN_TYPE or \
192186
method_result is None:
193-
print(type(class_instance), flush=True)
194187
return class_instance
195188

196-
return method_result
189+
return method_result

microservices/binary_executor_image/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import pandas as pd
99
import dill
1010
import os
11+
from tensorflow import keras
12+
import traceback
1113

1214

1315
class Database:
@@ -197,10 +199,8 @@ def save(self, instance: object, filename: str, service_type: str) -> None:
197199
os.makedirs(os.path.dirname(model_output_path))
198200

199201
try:
200-
from tensorflow import keras
201202
keras.models.save_model(instance, model_output_path)
202203
except Exception:
203-
import traceback
204204
traceback.print_exc()
205205
model_output = open(model_output_path,
206206
self.__WRITE_MODEL_OBJECT_OPTION)
@@ -217,7 +217,7 @@ def read(self, filename, service_type: str) -> object:
217217
self.__READ_MODEL_OBJECT_OPTION)
218218
return dill.load(model_binary_instance)
219219
except Exception:
220-
from tensorflow import keras
220+
traceback.print_exc()
221221
return keras.models.load_model(binary_path)
222222

223223
def delete(self, filename: str, service_type: str) -> None:

microservices/code_executor_image/code_execution.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import sys
66
import validators
77
import requests
8+
import tensorflow
9+
import traceback
810

911

1012
class Function:
@@ -73,7 +75,6 @@ def __get_a_class_instance(self, class_code: str) -> object:
7375
self.__CLASS_INSTANCE_CHARACTER,
7476
f'{class_instance_name}=')
7577

76-
import tensorflow
7778
exec(class_code, locals(), context_variables)
7879

7980
return context_variables[class_instance_name]
@@ -133,10 +134,6 @@ def create(self,
133134
function,
134135
function_parameters,
135136
description)
136-
self.__pipeline(
137-
function,
138-
function_parameters,
139-
description)
140137

141138
def update(self,
142139
function: str,
@@ -192,6 +189,7 @@ def __execute_function(self, function: str,
192189
return context_variables["response"], function_message, None
193190

194191
except Exception as error:
192+
traceback.print_exc()
195193
function_message = redirected_output.getvalue()
196194
sys.stdout = old_stdout
197195
function_error = repr(error)

microservices/code_executor_image/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import pandas as pd
77
import os
88
import dill
9-
import inspect
9+
import traceback
10+
from tensorflow import keras
1011

1112

1213
class Database:
@@ -179,16 +180,16 @@ def read(self, filename: str, service_type: str) -> object:
179180
self.__READ_OBJECT_OPTION)
180181
return dill.load(model_binary_instance)
181182
except Exception:
182-
from tensorflow import keras
183+
traceback.print_exc()
183184
return keras.models.load_model(binary_path)
184185

185186
def save(self, instance: object, filename: str) -> None:
186187
output_path = ObjectStorage.get_write_binary_path(filename)
187188

188189
try:
189-
from tensorflow import keras
190190
keras.models.save_model(instance, output_path)
191191
except Exception:
192+
traceback.print_exc()
192193
instance_output = open(output_path,
193194
self.__WRITE_OBJECT_OPTION)
194195
dill.dump(instance, instance_output)

microservices/database_executor_image/database_execution.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from utils import Database, ExecutionStorage, Metadata, Data
33
import importlib
44
from constants import Constants
5+
import traceback
56

67

78
class Parameters:
@@ -165,6 +166,7 @@ def __pipeline(self,
165166
flag=True)
166167

167168
except Exception as exception:
169+
traceback.print_exc()
168170
self.__metadata_creator.create_execution_document(
169171
self.filename,
170172
description,

microservices/database_executor_image/utils.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import os
1010
import seaborn as sns
1111
import dill
12+
import traceback
13+
from tensorflow import keras
1214

1315

1416
class Database:
@@ -241,20 +243,29 @@ def __init__(self, database_connector: Database):
241243
self.__database_connector = database_connector
242244
self.__thread_pool = ThreadPoolExecutor()
243245

246+
def read(self, filename: str, service_type: str) -> object:
247+
binary_path = TransformStorage.get_read_binary_path(
248+
filename, service_type)
249+
try:
250+
binary_instance = open(
251+
binary_path,
252+
self.__READ_OBJECT_OPTION)
253+
return dill.load(binary_instance)
254+
except Exception:
255+
traceback.print_exc()
256+
return keras.models.load_model(binary_path)
257+
244258
def save(self, instance: object, filename: str) -> None:
245259
output_path = TransformStorage.get_write_binary_path(filename)
246260

247-
instance_output = open(output_path,
248-
self.__WRITE_OBJECT_OPTION)
249-
dill.dump(instance, instance_output)
250-
instance_output.close()
251-
252-
def read(self, filename: str, service_type: str) -> object:
253-
binary_instance = open(
254-
TransformStorage.get_read_binary_path(
255-
filename, service_type),
256-
self.__READ_OBJECT_OPTION)
257-
return dill.load(binary_instance)
261+
try:
262+
keras.models.save_model(instance, output_path)
263+
except Exception:
264+
traceback.print_exc()
265+
instance_output = open(output_path,
266+
self.__WRITE_OBJECT_OPTION)
267+
dill.dump(instance, instance_output)
268+
instance_output.close()
258269

259270
def delete(self, filename: str) -> None:
260271
self.__thread_pool.submit(

microservices/model_image/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from concurrent.futures import ThreadPoolExecutor
33
from utils import Metadata, Database, ObjectStorage, Data
44
from constants import Constants
5+
import traceback
6+
import tensorflow
57

68

79
class Parameters:
@@ -57,7 +59,6 @@ def __get_a_class_instance(self, class_code: str) -> object:
5759
self.__CLASS_INSTANCE_CHARACTER,
5860
f'{class_instance_name}=')
5961

60-
import tensorflow
6162
exec(class_code, locals(), context_variables)
6263

6364
return context_variables[class_instance_name]
@@ -141,6 +142,7 @@ def __pipeline(self,
141142
self.__metadata_creator.update_finished_flag(self.model_name,
142143
flag=True)
143144
except Exception as exception:
145+
traceback.print_exc()
144146
self.__metadata_creator.create_model_document(self.model_name,
145147
description,
146148
class_parameters,

microservices/model_image/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import dill
99
import os
1010
import pandas as pd
11+
from tensorflow import keras
12+
import traceback
1113

1214

1315
class Database:
@@ -190,7 +192,7 @@ def read(self, filename: str, service_type: str) -> object:
190192
self.__READ_OBJECT_OPTION)
191193
return dill.load(model_binary_instance)
192194
except Exception:
193-
from tensorflow import keras
195+
traceback.print_exc()
194196
return keras.models.load_model(binary_path)
195197

196198
def save(self, filename: str, instance: object, service_type) -> None:

0 commit comments

Comments
 (0)