Hello,
I have a use-case where I want to copy firmware to a bunch of wireless controllers (mc’s) using the Aruba AOS API. The API call works and I could just run my script on all controllers one at a time. However as the transfer can take 10 minutes or longer on each controller it would be nice to speed that up by using some kind of multi-threading. My Python skills only extend to small scripts, and I haven’t touched multi-threading before so apologies for the noob nature of this.
So the basics of what I want to do are to run the file transfer API call on a list of controller IPs and for that to run in some kind of interleaved way that means all of the file transfers are started without having to wait for the previous transfers to finish.
After reading a couple of tutorials it seemed like concurrent.futures.ThreadPoolExecutor might help but can’t get it to work - it ran ok and it looped through the controllers but it was still only dealing with one file transfer call at a time before moving onto the next. I simiplified it so that instead of making any API calls it just runs a wait() function that calls sleep():
From main() (this is a snippet but hopefully includes the important bits):
x = 0 # Using threads with concurrent.futures.ThreadPoolExecutor(max_workers=len(mc_list)) as executor:for mc in mc_list: x+=1 print(f'\nprocessing {mc}') executor.submit(wait(),x)
def wait(): sleep(30)
This has the same problem, it just waits for 30 seconds before running again with the next controller (mc).
Can someone point me in the right direction please?! Have I misunderstood what ThreadPoolExecutor is used for?
I’ve heard mention of asyncio but I was hoping I could just get this to work before investigating something new!
Guy