__del__ pattern?

Peter Hansen peter at engcorp.com
Mon Aug 15 21:26:59 EDT 2005


Tom Anderson wrote:
> Only one socket can be bound to a given port at any time, so the second 
> instance of SpecialClass will get an exception from the bind call, and 
> will be stillborn. This is a bit of a crufty hack, though - you end up 
> with an open port on your machine for no good reason. If 

If you bind with self.sock.bind(('localhost', 4242)) instead, at least 
you don't have much of a security risk since the port won't be available 
for connections from outside the same machine.  Using '' instead of 
'localhost' means bind to *all* interfaces, not just the loopback one.

-Peter



More information about the Python-list mailing list