Skip to content

Commit

Permalink
Fix an issue where MacOS blocks port 5000. When not using developer m…
Browse files Browse the repository at this point in the history
…ode, MOSAIC assigns a random available port for the web UI.
  • Loading branch information
abalijepalli committed Apr 27, 2022
1 parent 6f34f9a commit 7f271ad
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions mosaicweb/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,32 @@ def load(self):

@registerLaunch("mweb")
def startMOSAICWeb(newWindow=True):
webbrowser.open("http://localhost:{0}/".format(mosaic.WebServerPort), new=newWindow, autoraise=True)
if mosaic.DeveloperMode:
WebServerPort=mosaic.WebServerPort
else:
WebServerPort=getAvailablePort()

webbrowser.open("http://localhost:{0}/".format(WebServerPort), new=newWindow, autoraise=True)

# Setup platform-dependent timing function
if sys.platform.startswith('win'):
app.run(host=mosaic.WebHost, port=mosaic.WebServerPort, debug=mosaic.DeveloperMode)
app.run(host=mosaic.WebHost, port=WebServerPort, debug=mosaic.DeveloperMode)
else:
mosaicApp=mosaicApplication(mosaicweb.app, {
'bind' : '%s:%s' % (mosaic.WebHost, mosaic.WebServerPort),
'bind' : '%s:%s' % (mosaic.WebHost, WebServerPort),
'workers' : mosaic.WebServerWorkers
})
mosaicApp.run()


def getAvailablePort():
from socket import socket

with socket() as s:
s.bind(('',0))

port=s.getsockname()[1]

return port


0 comments on commit 7f271ad

Please sign in to comment.