Make sure the socket's used are closed

This commit is contained in:
Pedro Algarvio 2017-04-04 19:28:06 +01:00
parent 7b713d9256
commit c3417213d7
No known key found for this signature in database
GPG Key ID: BB36BF6584A298FF

View File

@ -552,11 +552,10 @@ def requires_network(only_local_network=False):
'173.194.41.201', '173.194.41.206', '173.194.41.192', '173.194.41.201', '173.194.41.206', '173.194.41.192',
'173.194.41.193', '173.194.41.194', '173.194.41.195', '173.194.41.193', '173.194.41.194', '173.194.41.195',
'173.194.41.196', '173.194.41.197'): '173.194.41.196', '173.194.41.197'):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.settimeout(0.25) sock.settimeout(0.25)
sock.connect((addr, 80)) sock.connect((addr, 80))
sock.close()
# We connected? Stop the loop # We connected? Stop the loop
break break
except socket.error: except socket.error:
@ -564,6 +563,8 @@ def requires_network(only_local_network=False):
continue continue
else: else:
cls.skipTest('No internet network connection was detected') cls.skipTest('No internet network connection was detected')
finally:
sock.close()
return func(cls) return func(cls)
return wrapper return wrapper
return decorator return decorator