mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed "Address already in use" from liveserver.
Our WSGIServer rewrapped the socket errors from server_bind into WSGIServerExceptions, which is used later on to provide nicer error messages in runserver and used by the liveserver to see if the port is already in use. But wrapping server_bind isn't enough since it only binds to the socket, socket.listen (which is called from server_activate) could also raise "Address already in use". Instead of overriding server_activate too I chose to just catch socket errors, which seems to make more sense anyways and should be more robust against changes in wsgiref.
This commit is contained in:
@@ -8,6 +8,7 @@ import json
|
||||
import os
|
||||
import posixpath
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
import unittest
|
||||
@@ -21,8 +22,7 @@ from django.core.handlers.wsgi import get_path_info, WSGIHandler
|
||||
from django.core.management import call_command
|
||||
from django.core.management.color import no_style
|
||||
from django.core.management.commands import flush
|
||||
from django.core.servers.basehttp import (WSGIRequestHandler, WSGIServer,
|
||||
WSGIServerException)
|
||||
from django.core.servers.basehttp import WSGIRequestHandler, WSGIServer
|
||||
from django.core.urlresolvers import clear_url_caches, set_urlconf
|
||||
from django.db import connection, connections, DEFAULT_DB_ALIAS, transaction
|
||||
from django.db.models.loading import cache
|
||||
@@ -1028,10 +1028,9 @@ class LiveServerThread(threading.Thread):
|
||||
try:
|
||||
self.httpd = WSGIServer(
|
||||
(self.host, port), QuietWSGIRequestHandler)
|
||||
except WSGIServerException as e:
|
||||
except socket.error as e:
|
||||
if (index + 1 < len(self.possible_ports) and
|
||||
hasattr(e.args[0], 'errno') and
|
||||
e.args[0].errno == errno.EADDRINUSE):
|
||||
e.errno == errno.EADDRINUSE):
|
||||
# This port is already in use, so we go on and try with
|
||||
# the next one in the list.
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user