Permalink
Browse files

Autotry additional ports if 8888 if already in use.

  • Loading branch information...
1 parent f5c5121 commit d1499b6197069912c8789337940306f204266c32 @ellisonbg ellisonbg committed Aug 15, 2011
Showing with 14 additions and 1 deletion.
  1. +14 −1 IPython/frontend/html/notebook/notebookapp.py
@@ -11,9 +11,11 @@
# Imports
#-----------------------------------------------------------------------------
+import errno
import logging
import os
import signal
+import socket
import sys
import zmq
@@ -213,7 +215,18 @@ def initialize(self, argv=None):
self.log.critical('WARNING: the notebook server is listening on all IP addresses '
'but not using any encryption or authentication. This is highly '
'insecure and not recommended.')
- self.http_server.listen(self.port, self.ip)
+ for i in range(10):
+ try:
+ port = self.port + i
+ self.http_server.listen(port, self.ip)
+ except socket.error, e:
+ if e.errno != errno.EADDRINUSE:
+ raise
+ self.log.info('The port %i is already in use, trying: %i' % (port, port+1))
+ else:
+ self.port = port
+ break
+
def start(self):
ip = self.ip if self.ip else '[all ip addresses on your system]'

0 comments on commit d1499b6

Please sign in to comment.