Python 2.4 and os.open question?

  • Thread starter =?ISO-8859-1?Q?Eino_M=E4kitalo?=
  • Start date
?

=?ISO-8859-1?Q?Eino_M=E4kitalo?=

I just test in Windows XP with Python 2.4

I'd like to create a file with exclusive flag.
If file exist I try to use it, if not I'd like to create it.
Python (and underlying library) works differently with/without O_EXCL
flag. Is this okay. How I should use this.

Has somebody manual :) ?

Eino Mäkitalo

see scenarios (1 without flag ) (2 with flag)

Scenario 1:

To create file if it's not available this works ok


Scenario 2:
But if you try to do same with O_EXCL then it does not use same logic???
Traceback (most recent call last):
File "<string>", line 1, in <string>
OSError: [Errno 17] File exists: 'c:\\temp\\a.txt'
 
A

Antoon Pardon

Op 2005-01-11 said:
I just test in Windows XP with Python 2.4

I'd like to create a file with exclusive flag.

Why? What is it about the exclusive flag that
makes you like to use it?
If file exist I try to use it, if not I'd like to create it.

If you want that, you cant use the exclusive flag.
Python (and underlying library) works differently with/without O_EXCL
flag.

Well if the absence and presence of this flag wouldn't make a
difference, it would hardly be usefull to have such a flag,
wouldn't it?
Is this okay. How I should use this.

Has somebody manual :) ?

Eino Mäkitalo

see scenarios (1 without flag ) (2 with flag)

Scenario 1:

To create file if it's not available this works ok



Scenario 2:
But if you try to do same with O_EXCL then it does not use same logic???

That is what flags are for: to change the logic. O_EXCL, makes sure
you are the one that creats the file. If the file exists it fails.
This is to make sure that if two programs can create the same file
but shouldn't work on it the same time, the file isn't opened
multiple times.

I suppose this should again be the instrcution two lines above;
this actually works. (At least on my linux box, if it didn't on
your XP box, that is a bug)
Traceback (most recent call last):
File "<string>", line 1, in <string>
OSError: [Errno 17] File exists: 'c:\\temp\\a.txt'

Which is exactly as it should, provided you actually used the os.O_EXCL
flag twice.
 
?

=?ISO-8859-1?Q?Eino_M=E4kitalo?=

Antoon said:
Why? What is it about the exclusive flag that
makes you like to use it?

Ok. Thanks, I misunderstood the meaning of flag.
What I' like to do is to open file and keep it exclusive locked for me.
Apparently this flag is not for me.

Eino Mäkitalo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top