UpCloudLtd/upcloud-python-api

How to start many servers simultaneously?

Closed this issue · 1 comments

Hi, currently we have an operation where we wish to start many servers (e.g. 30+ servers) at once. The stop() method seems to respond once the server is being stopped but the start() method seems to block until the server is fully started which means starting them one by one would take a while. We have code that waits for all of them to reach certain state but it is not as useful for the start() method as they would have most likely already been started.

Is there a way to have start() behave like the stop() method or something that achieves similar result?

I used the following snippet and it seems to work fine for me.

from threading import Thread

...

tasks = []
for uuid in uuids:
    server = manager.get_server(uuid)
    tasks.append(Thread(target=server.start))

for task in tasks:
    task.start()

for task in tasks:
    task.join()