Hi, While porting python-openid and doing regress tests I had a strange behavior with getsockname function and threads. One test (test_fetchers) create an http server with HTTPServer class and put it in a thread before lauching tests. Theses tests get the server port thanks to getsockname() function. The problem is that just right after the server is started, getsockname return nothing and block other actions, http server continue to run. Here is a little code to reproduce it :
-------------------------------------- start import os, socket from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import threading host = socket.getfqdn('127.0.0.1') port = (os.getpid() % 31000) + 1024 server = HTTPServer((host, port), BaseHTTPRequestHandler) print "before:" print server.socket.getsockname()[1] server_thread = threading.Thread(target=server.serve_forever) server_thread.setDaemon(1) server_thread.start() print "after:" print server.socket.getsockname()[] print "ok" -------------------------------------- end of code On 4.2 & -current, if you execute this code you get this result : ------- before: <numofport> after: -------- After the line "after", nothing appear and http server continue to run. If you access it with a browser or telnet then the script end and you finaly have getsockname return and "ok" line. If you remove getsockname line everything is ok. So it seems that getsockname block the thread or something like it. Is this a bug ? I reproduced this behaviour on macppc and amd64. Benoit