4
Wolle
5y

If got this code with the 20second sleep statement. And I am not really sure if it is a good idea to have it ...

def start_instance(self):
instance=self.ec2.Instance(self.iId)
instance.start()
while instance.state['Name'] != 'running':
sleep(5)
instance=self.ec2.Instance(self.iId)
sleep(20) #Let's sleep another 20 for the server to be really up
return instance.state

Can I have some advice regarding best practices?

Comments
  • 1
    Could you ping the server instead?
  • 0
    @gruff No, outbound ping are blocked by the corporate firewall.
  • 2
    If there is no way to check whether the server is up, you should at least measure the average time it takes and add an error margin, instead of just doing a rough estimation, which could cost you quite some time
Add Comment