Reputation: 3
With my portion of the code below using concurrent.futures.ThreadPoolExecutor
if __name__ == "__main__":
xw.Book("Main_Template.xlsm").set_mock_caller()
test1 = CombineCodes()
try:
with open("output.txt", 'w') as writefile:
with ThreadPoolExecutor() as executor:
results = executor.map(test1.code, test1.v_hostname_ip)
for result in results:
writefile.write(result)
end = perf_counter()
total_time = end - start
print(total_time)
writefile.close()
except Exception:
with open("output.txt", 'a') as writefile1:
error = """VALUE ERROR on Excel input items! OR Device is
unreachable!\nPlease check/verify the following:
\t -On Device, Test if DEVICE is reachable
\t -On Excel, Check if "SHOW_OR_CHANGE" ITEMS has value
\t -On Excel, Check if other VALUES on COLUMN has values?"""
print(error)
writefile1.write(error)
writefile1.close()
With the "test1.v_hostname_ip" as test1.code argument, If let us say i have 4 network devices 1.1.1.1, 1.1.1.2, 1.1.1.3, 1.1.1.4, 1.1.1.5 and 1.1.1.3 is unreachable, it goes to the EXCEPTION right away and no longer continue with 1.1.1.4 etc.
How can i be able to still write the exception message to the "output.txt" while still continuing with the program if one of the devices on the list is unreachable or has timed out?
Upvotes: 0
Views: 18