code: def pick_unused_port(self):
      
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.bind(('127.0.0.1', 0))
      _, port = s.getsockname()
      s.close()
      return port
docs: Pick an unused port. There is a slight chance that this wont work.