import random, threading, webbrowser
port = 5000 + random.randint(0, 999)
url = 'http://127.0.0.1:{0}'.format(port)
threading.Timer(1.25, lambda : webbrowser.open(url)).start()
Python - Flask - open a webpage in default browser