~the-test-people/selenium-simple-test/internal

« back to all changes in this revision

Viewing changes to src/sst/tests/__init__.py

  • Committer: Peter Russell
  • Date: 2014-02-25 15:26:23 UTC
  • mto: This revision was merged to the branch mainline in revision 510.
  • Revision ID: peter.russell@thetestpeople.com-20140225152623-kta9riezp9uo7fcr
When trying to detect if Django is running, don't set SO_REUSEADDR on Windows.

Setting SO_REUSEADDR on a socket on Windows, allows the port to be reused
as well, meaning that it's not a good way of detecting if the port is in
use.  But Windows allows binding even when the port is in the wait state,
so we don't need it anyway.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import inspect
20
20
import os
 
21
import platform
21
22
import shutil
22
23
import socket
23
24
import sys
95
96
    """check if port is ok to use for django devserver"""
96
97
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
97
98
    # immediately reuse a local socket in TIME_WAIT state
98
 
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 
99
    if platform.system() != 'Windows':
 
100
        # The behaviour of Windows without SO_REUSEADDR is similar to *NIX
 
101
        # with it, see http://stackoverflow.com/questions/4979425
 
102
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
99
103
    try:
100
104
        sock.bind(('127.0.0.1', port))
101
105
        used = False