Show More
@@ -522,6 +522,30 b' class NotebookApp(BaseIPythonApplication):' | |||||
522 | try: |
|
522 | try: | |
523 | self.http_server.listen(port, self.ip) |
|
523 | self.http_server.listen(port, self.ip) | |
524 | except socket.error as e: |
|
524 | except socket.error as e: | |
|
525 | # XXX: remove the e.errno == -9 block when we require | |||
|
526 | # tornado >= 3.0 | |||
|
527 | if e.errno == -9: | |||
|
528 | # The flags passed to socket.getaddrinfo from | |||
|
529 | # tornado.netutils.bind_sockets can cause "gaierror: | |||
|
530 | # [Errno -9] Address family for hostname not supported" | |||
|
531 | # when the interface is not associated, for example. | |||
|
532 | # Changing the flags to exclude socket.AI_ADDRCONFIG does | |||
|
533 | # not cause this error, but the only way to do this is to | |||
|
534 | # monkeypatch socket to remove the AI_ADDRCONFIG attribute | |||
|
535 | saved_AI_ADDRCONFIG = socket.AI_ADDRCONFIG | |||
|
536 | self.log.info('Monkeypatching socket to fix tornado bug') | |||
|
537 | del(socket.AI_ADDRCONFIG) | |||
|
538 | try: | |||
|
539 | # retry the tornado call without AI_ADDRCONFIG flags | |||
|
540 | self.http_server.listen(port, self.ip) | |||
|
541 | except socket.error as e2: | |||
|
542 | e = e2 | |||
|
543 | else: | |||
|
544 | self.port = port | |||
|
545 | success = True | |||
|
546 | break | |||
|
547 | # restore the monekypatch | |||
|
548 | socket.AI_ADDRCONFIG = saved_AI_ADDRCONFIG | |||
525 | if e.errno != errno.EADDRINUSE: |
|
549 | if e.errno != errno.EADDRINUSE: | |
526 | raise |
|
550 | raise | |
527 | self.log.info('The port %i is already in use, trying another random port.' % port) |
|
551 | self.log.info('The port %i is already in use, trying another random port.' % port) |
General Comments 0
You need to be logged in to leave comments.
Login now