Skip to content

Commit

Permalink
Opens a browser window when launching the server
Browse files Browse the repository at this point in the history
There shouldn't be any race conditions here because we're
opening the browser after the server starts listening but
before the event loop runs.
  • Loading branch information
njvrzm committed Oct 16, 2016
1 parent 5f39954 commit 97f7512
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mesa/visualization/ModularVisualization.py
Expand Up @@ -81,12 +81,13 @@
import os

import tornado.ioloop
import tornado.template
import tornado.web
import tornado.websocket
import tornado.escape
import tornado.gen

import webbrowser

# Suppress several pylint warnings for this file.
# Attributes being defined outside of init is a Tornado feature.
# pylint: disable=attribute-defined-outside-init
Expand Down Expand Up @@ -255,6 +256,8 @@ def launch(self, port=None):
""" Run the app. """
if port is not None:
self.port = port
print('Interface starting at http://127.0.0.1:{PORT}'.format(PORT=self.port))
url = 'http://127.0.0.1:{PORT}'.format(PORT=self.port)
print('Interface starting at {url}'.format(url=url))
self.listen(self.port)
webbrowser.open(url)
tornado.ioloop.IOLoop.instance().start()

0 comments on commit 97f7512

Please sign in to comment.