Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion toolset/benchmark/benchmarker.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ def __run_tests(self, tests):
test_process = Process(target=self.__run_test, args=(test,))
test_process.start()
test_process.join(self.run_test_timeout_seconds)
self.__load_results() # Load intermediate result from child process
if(test_process.is_alive()):
logging.debug("Child process for {name} is still alive. Terminating.".format(name=test.name))
self.__write_intermediate_results(test.name,"__run_test timeout (="+ str(self.run_test_timeout_seconds) + " seconds)")
Expand Down Expand Up @@ -571,7 +572,7 @@ def __run_test(self, test):
p.communicate("""
sudo restart mysql
sudo restart mongodb
sudo /etc/init.d/postgresql restart
sudo /etc/init.d/postgresql restart
""")
time.sleep(10)

Expand Down Expand Up @@ -828,6 +829,15 @@ def __write_intermediate_results(self,test_name,status_message):
# End __write_intermediate_results
############################################################

def __load_results(self):
try:
with open(os.path.join(self.latest_results_directory, 'results.json')) as f:
results = json.load(f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, this line creates potential to experience UnboundLocalVariable, which I just experienced by trying to add log.debug("Before load %s" % str(results)). Not sure if there's a way to ensure this doesn't happen to anyone else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could use a local variable named something other than results?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so my python knowledge isn't deep. I could easily fix this by using self.results instead of trying to print the results variable. However, it may still be useful to rename that local variable just to avoid any future problems

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else: clause of try: statement will be executed only when try: block finished without any exception.
But it's not easy to understand for person from other languages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing wrong with the logic here, I'm saying that perhaps it's not a good choice to have a variable self.results and a variable results, they are easily confused. Perhaps rename results

except (ValueError, IOError):
pass
else:
self.results = results

############################################################
# __finish
############################################################
Expand Down