closing a server socket

Peter Hansen peter at engcorp.com
Tue Oct 14 10:19:43 EDT 2003


simon place wrote:
> 
> Spent some very frustrating hours recoding to find a way of closing a server
> socket, i'd not thought it would be any problem,
> 
> however, after complete failure and as a last resort, i looked at the python
> wrapper module for sockets, and found that the close command doesn't actually
> call the underlying close! this didn't seem right, so i added it, and my code
> now works simply and as expected.
> 
>         def close(self):
>                 self._sock.close()  # added 2003-oct-13
>                 self._sock = _closedsocket()
>                 self.send = self.recv = self.sendto = self.recvfrom =           self._sock._dummy
>                 close.__doc__ = _realsocket.close.__doc__
> 
> Probably only on win32, the comments in the socket module seem to indicate
> different codings on different platforms.

None of this should be necessary!

What problems were you having that led you to try the above abomination in
your effort to resolve them?

-Peter




More information about the Python-list mailing list