enough-analyst-54434
07/08/2018, 1:11 PMimport atexit, socket
sockets = []
atexit.register(lambda: [ss.close() for ss in sockets])
for i in xrange(2**16):
print('Socket bind attempt #{}'.format(str(i)))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockets.append(s)
s.bind(('localhost', 0))
_, port = s.getsockname()
print(' ... bound port {}'.format(port))
I get:
python /tmp/test.py
...
Socket bind attempt #28230
... bound port 54742
Socket bind attempt #28231
... bound port 54750
Socket bind attempt #28232
Traceback (most recent call last):
File "/tmp/test.py", line 14, in <module>
s.bind(('localhost', 0))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
I'm guessing Nora hasn't rebooted in a while.