Re: __del__ pattern?

2005-08-21 Thread Jorgen Grahn
On Tue, 16 Aug 2005 08:03:58 -0400, Peter Hansen [EMAIL PROTECTED] wrote: Tom Anderson wrote: On Mon, 15 Aug 2005, Peter Hansen wrote: Using '' instead of 'localhost' means bind to *all* interfaces, not just the loopback one. Doesn't '' mean 'bind to the *default* interface'? What does

Re: __del__ pattern?

2005-08-19 Thread Bryan Olson
BranoZ wrote: [EMAIL PROTECTED] wrote: For a reasonably portable solution, leave the lock file open. On most systems, you cannot delete an open file,.. On most UNIXes, you can delete an open file. Even flock-ed. This is BTW also an hack around flock. Yes, sorry; my bad. Use file

Re: __del__ pattern?

2005-08-19 Thread BranoZ
Bryan Olson wrote: Use file that is writeable by A and B in a directory that is writeable only by root. Is that portable? I have the feeling that you are asking if it works on Windows. No idea! I have only user experience with Windows. On UNIX it is as portable as 'flock', which means

Re: __del__ pattern?

2005-08-16 Thread Tom Anderson
On Mon, 15 Aug 2005, Peter Hansen wrote: 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

Re: __del__ pattern?

2005-08-16 Thread Peter Hansen
Tom Anderson wrote: On Mon, 15 Aug 2005, Peter Hansen wrote: Using '' instead of 'localhost' means bind to *all* interfaces, not just the loopback one. Doesn't '' mean 'bind to the *default* interface'? What does default mean, and is that definition in conflict with what I said? The docs

Re: __del__ pattern?

2005-08-16 Thread Dan
What does default mean, and is that definition in conflict with what I said? The docs say it means INADDR_ANY. someSocket.bind(('', somePort)) means accept connections from any machine. (We use INADDR_ANY instead of '' in C.) someSocket.bind(('localhost', somePort)) means accept only

Re: __del__ pattern?

2005-08-16 Thread bryanjugglercryptographer
Tom Anderson wrote: On Mon, 15 Aug 2005, Chris Curvey wrote: Is there a better pattern to follow than using a __del__ method? I just need to be absolutely, positively sure of two things: An old hack i've seen before is to create a server socket - ie, make a socket and bind it to a port:

Re: __del__ pattern?

2005-08-16 Thread Peter Hansen
Dan wrote: someSocket.bind(('localhost', somePort)) means accept only connections from the local machine. Almost: accept only attempts to connect *to* localhost, from the local machine. Attempting to connect -- even locally -- using one of the IP addresses bound to an external interface will

Re: __del__ pattern?

2005-08-16 Thread bryanjugglercryptographer
Chris Curvey wrote: I need to ensure that there is only one instance of my python class on my machine at a given time. (Not within an interpreter -- that would just be a singleton -- but on the machine.) These instances are created and destroyed, but there can be only one at a time. So

Re: __del__ pattern?

2005-08-16 Thread BranoZ
[EMAIL PROTECTED] wrote: For a reasonably portable solution, leave the lock file open. On most systems, you cannot delete an open file,.. On most UNIXes, you can delete an open file. Even flock-ed. This is BTW also an hack around flock. 1. Process A opens file /var/tmp/test1, and flocks

Re: __del__ pattern?

2005-08-16 Thread Michael Hudson
[EMAIL PROTECTED] writes: Chris Curvey wrote: I need to ensure that there is only one instance of my python class on my machine at a given time. (Not within an interpreter -- that would just be a singleton -- but on the machine.) These instances are created and destroyed, but there can be

Re: __del__ pattern?

2005-08-15 Thread BranoZ
So when my class is instantiated, I create a little lock file, and I have a __del__ method that deletes the lock file. Unfortunately, there seem to be some circumstances where my lock file is not getting deleted. Maybe the interpreter died by the signal.. in that case the __del__ is not

Re: __del__ pattern?

2005-08-15 Thread Michael Hudson
Chris Curvey [EMAIL PROTECTED] writes: I need to ensure that there is only one instance of my python class on my machine at a given time. I recommend modifying your requirements such that you ensure that there is only one active instance of your class at any one time (or something like that),

Re: __del__ pattern?

2005-08-15 Thread Tom Anderson
On Mon, 15 Aug 2005, Chris Curvey wrote: Is there a better pattern to follow than using a __del__ method? I just need to be absolutely, positively sure of two things: An old hack i've seen before is to create a server socket - ie, make a socket and bind it to a port: import socket class

Re: __del__ pattern?

2005-08-15 Thread Peter Hansen
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