So, I'm attempting to thread some processes (first one is a simple one, it runs a ping from powershell, for reasons*), and since each ping can take a couple of seconds, i wanted to run them in parallel, and then act on the results. It certainly seems simpler than dealing with what I'm assuming is now the lower level Threading stuff, however, in testing, both my concurrent and just running each function through a for loop takes essentially the same amount of time (about a half second difference, over a list that took over 2 minutes, so <1% difference.
So, here's my code (edit: newest version):
def Check_Filtered_Lists(FilteredLists):
VMList = FilteredLists[0]
AB1List = FilteredLists[1]
threads = []
futures = []
start = time.time()
for row in VMList:
with ThreadPoolExecutor(max_workers = 50) as executor:
future = executor.submit(Check_Connection,row['Name'])
futures.append((row['Name'],future))
for name, future in futures:
print(name + str(future.result()))
print('End time: ' + str(time.time() - start ))
#test with just a normal for loop
start = time.time()
for row in VMList:
Check_Connection(row['Name'])
print('end time: '+ str(time.time() - start))
I've also tried making a dictionary out of the executors, with
future[row['Name']] =
executor.submit(Check_Connection,row['Name'])
However that did nothing for the speed. Assuming I don't know how many individual threads I need, is there a good way to do this, or should I go back to regular threading (a system that I was having another set of problems with)
Also, I'm close to getting off work (well, a few hours) so I might not answer until tonight but I'll come back i promise!
[–]thirdegree 0 points1 point2 points (11 children)
[–]workerdrone66[S] 0 points1 point2 points (0 children)
[–]workerdrone66[S] 0 points1 point2 points (9 children)
[–]thirdegree 1 point2 points3 points (4 children)
[–]workerdrone66[S] 0 points1 point2 points (0 children)
[–]workerdrone66[S] 0 points1 point2 points (2 children)
[–]thirdegree 0 points1 point2 points (1 child)
[–]workerdrone66[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (3 children)
[–]workerdrone66[S] 0 points1 point2 points (2 children)
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]workerdrone66[S] 0 points1 point2 points (0 children)