Martin Panter added the comment:

The getpeername() method is just a wrapper around the OS function, so it is not 
going to work if the socket file descriptor is closed or invalid (-1).

You haven’t provided enough code or information for someone else to reproduce 
the problem. But it sounds like you may be closing the socket in one thread, 
and trying to use it in another thread. This is going to be unreliable and 
racy, depending on which thread acts on the socket first. Perhaps you should 
save the peer address in the same thread that closes it, so you can guarantee 
when it is open and when it is closed. Or use something else to synchronize the 
two threads and ensure the socket is always closed after getpeername() is 

BTW it looks like I have to remove George’s username from the nosy list because 
it contains a comma!

nosy: +martin.panter -George,Y
resolution:  -> not a bug

Python tracker <>
Python-bugs-list mailing list

Reply via email to