Show More
@@ -114,13 +114,17 wifexited = getattr(os, "WIFEXITED", lam | |||||
114 |
|
114 | |||
115 | def checkportisavailable(port): |
|
115 | def checkportisavailable(port): | |
116 | """return true if a port seems free to bind on localhost""" |
|
116 | """return true if a port seems free to bind on localhost""" | |
|
117 | families = [getattr(socket, i, None) | |||
|
118 | for i in ('AF_INET', 'AF_INET6') | |||
|
119 | if getattr(socket, i, None) is not None] | |||
|
120 | for family in families: | |||
117 | try: |
|
121 | try: | |
118 |
s = socket.socket( |
|
122 | s = socket.socket(family, socket.SOCK_STREAM) | |
119 | s.bind(('localhost', port)) |
|
123 | s.bind(('localhost', port)) | |
120 | s.close() |
|
124 | s.close() | |
121 | return True |
|
125 | return True | |
122 | except socket.error as exc: |
|
126 | except socket.error as exc: | |
123 |
if |
|
127 | if exc.errno not in (errno.EADDRINUSE, errno.EADDRNOTAVAIL): | |
124 | raise |
|
128 | raise | |
125 |
|
|
129 | return False | |
126 |
|
130 |
General Comments 0
You need to be logged in to leave comments.
Login now