Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Start webbrowser in a thread. Prevents lockup with Chrome. #936

Closed
wants to merge 1 commit into from

2 participants

Fernando Perez Min RK
Fernando Perez
Owner

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.

Fernando Perez fperez Start webbrowser in a thread. Prevents lockup with Chrome.
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.
9f23711
Min RK
Owner

Sensible, though note that it is actually only affects setting the BROWSER env to a blocking call. It does not affect Chrome, or any other browser, if it is the default system-wide as you suggest (assuming support for gnome-open or similar).

I actually was able to get the subprocess to survive notebook termination (at least with sigint/ctrl-C), with:

            def b():
                signal.signal(signal.SIGINT, signal.SIG_IGN)
                webbrowser.open("%s://%s:%i" % (proto, ip, self.port),
                                         new=2)
            p = multiprocessing.Process(target=b)
            p.daemon = True
            p.start()
Fernando Perez
Owner

Right on the system-wide setting, which is good.

I tried several approaches with subprocess and threading, but not the one with mp (I basically wrote the identical code you have with threading instead of mp). I'd say we go with that approach instead, as it will ultimately provide a better interface.

How does that sound? I can update the PR in a bit.
I'll

Fernando Perez
Owner

Mmh: I just implemented the code above, and I still get the Chrome session to die on my system (ubuntu 11.10, Chrome stable)... No luck, it dies just like with the threading or subprocess approach. Any chance when you were testing you had a Chrome process lying around beforehand? In that case it doesn't get killed...

Min RK
Owner

I did check, but I may not have been thorough. I honestly don't think it's a big deal - this is only going to affect users who don't actually use Chrome, but are running the notebook with Chrome (e.g. testers, like you). The more important thing is it starts up functional, which is resolved by the threading.

Since such users are few, and presumably fairly advanced, we can just note that using BROWSER='google-chrome&' (background) instead of BROWSER='google-chrome' should avoid the problem, though I'm not 100% sure it will be different from the multiprocessing behavior.

Fernando Perez
Owner
Fernando Perez
Owner

Rebased to avoid recursive merge, pushed.

Fernando Perez fperez closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 28, 2011
  1. Fernando Perez

    Start webbrowser in a thread. Prevents lockup with Chrome.

    fperez authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +8 −1 IPython/frontend/html/notebook/notebookapp.py
9 IPython/frontend/html/notebook/notebookapp.py
View
@@ -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
@@ -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,
@@ -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()
#-----------------------------------------------------------------------------
Something went wrong with that request. Please try again.