| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import atexit | 5 import atexit |
| 6 import datetime | 6 import datetime |
| 7 import email.utils | 7 import email.utils |
| 8 import errno | 8 import errno |
| 9 import hashlib | 9 import hashlib |
| 10 import logging | 10 import logging |
| 11 import math | 11 import math |
| 12 import os.path | 12 import os.path |
| 13 import socket | 13 import socket |
| 14 import subprocess | 14 import subprocess |
| 15 import sys |
| 15 import tempfile | 16 import tempfile |
| 16 import threading | 17 import threading |
| 17 | 18 |
| 18 import SimpleHTTPServer | 19 import SimpleHTTPServer |
| 19 import SocketServer | 20 import SocketServer |
| 20 | 21 |
| 21 _ZERO = datetime.timedelta(0) | 22 _ZERO = datetime.timedelta(0) |
| 22 | 23 |
| 23 | 24 |
| 24 class UTC_TZINFO(datetime.tzinfo): | 25 class UTC_TZINFO(datetime.tzinfo): |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 231 |
| 231 http_thread = threading.Thread(target=httpd.serve_forever) | 232 http_thread = threading.Thread(target=httpd.serve_forever) |
| 232 http_thread.daemon = True | 233 http_thread.daemon = True |
| 233 http_thread.start() | 234 http_thread.start() |
| 234 return httpd.server_address | 235 return httpd.server_address |
| 235 except socket.error as v: | 236 except socket.error as v: |
| 236 error_code = v[0] | 237 error_code = v[0] |
| 237 print 'Failed to start http server for %s on port %d: %s.' % ( | 238 print 'Failed to start http server for %s on port %d: %s.' % ( |
| 238 str(mappings), host_port, os.strerror(error_code)) | 239 str(mappings), host_port, os.strerror(error_code)) |
| 239 if error_code == errno.EADDRINUSE: | 240 if error_code == errno.EADDRINUSE: |
| 240 print (' Run `fuser %d/tcp` to find out which process is using the port;' | 241 if sys.platform == 'darwin': |
| 241 % host_port) | 242 find_cmd = 'lsof -i :%d' % host_port |
| 242 print (' or `fuser -k %d/tcp` terminate it.' % host_port) | 243 terminate_cmd = ( |
| 244 'lsof -i :%d | grep LISTEN | awk \'{print $2}\' | xargs kill -9' |
| 245 % host_port) |
| 246 else: |
| 247 find_cmd = 'fuser %d/tcp' % host_port |
| 248 terminate_cmd = 'fuser -k %d/tcp' % host_port |
| 249 print (' Run `%s` to find out which process is using the port;' |
| 250 % find_cmd) |
| 251 print (' or `%s` terminate it.' % terminate_cmd) |
| 243 print '---' | 252 print '---' |
| 244 raise | 253 raise |
| OLD | NEW |