Moved the following condition out of while loop which caused rest of the code to be shifted by two spaces.
if self.single_pass:
      self.RegenerateKeysAndCreateAccounts()
      return

In addition to that added a try catch around line 74 to catch unexpected exceptions and sleep for 5 seconds before retrying.