Skip to content

Commit

Permalink
Start webbrowser in a thread. Prevents lockup with Chrome.
Browse files Browse the repository at this point in the history
If a user has Chrome set as their default browser (system-wide or via
the `BROWSER` environment variable), opening the notebook hangs
because the chrome call doesn't return immediately.  This solves the
issue by opening the browser in a thread.

Note that there remains an issue where killing the notebook will kill
Chrome if the Chrome session was started by us.  I haven't found a way
to work around that despite attempts by making the webbrowser.open()
call in a subprocess.
  • Loading branch information
fperez committed Oct 28, 2011
1 parent 90b0139 commit 2178365
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion IPython/frontend/html/notebook/notebookapp.py
Expand Up @@ -16,14 +16,17 @@
# Imports
#-----------------------------------------------------------------------------

# stdlib
import errno
import logging
import os
import signal
import socket
import sys
import threading
import webbrowser

# Third party
import zmq

# Install the pyzmq ioloop. This has to be done before anything else from
Expand All @@ -35,6 +38,7 @@
from tornado import httpserver
from tornado import web

# Our own libraries
from .kernelmanager import MappingKernelManager
from .handlers import (LoginHandler,
ProjectDashboardHandler, NewHandler, NamedNotebookHandler,
Expand Down Expand Up @@ -301,7 +305,10 @@ def start(self):
self.port))
if self.open_browser:
ip = self.ip or '127.0.0.1'
webbrowser.open("%s://%s:%i" % (proto, ip, self.port), new=2)
b = lambda : webbrowser.open("%s://%s:%i" % (proto, ip, self.port),
new=2)
threading.Thread(target=b).start()

ioloop.IOLoop.instance().start()

#-----------------------------------------------------------------------------
Expand Down

0 comments on commit 2178365

Please sign in to comment.