Because of multithreading semantics, this is not reliable.

Christophe chris.cavalaria at
Thu May 4 16:14:07 CEST 2006

OlafMeding at a écrit :
> Christophe
>>Same reason that there is a warning in the "os.access" manual
> I understand the if file exists open it code.
> I looked at the os.access documentation and see no "warning" or "not
> reliable" wording there.
>   6.1.4 Files and Directories
>   access(path, mode)
> Olaf

6.1.4 Files and Directories

access( path, mode)

Use the real uid/gid to test for access to path. Note that most 
operations will use the effective uid/gid, therefore this routine can be 
used in a suid/sgid environment to test if the invoking user has the 
specified access to path. mode should be F_OK to test the existence of 
path, or it can be the inclusive OR of one or more of R_OK, W_OK, and 
X_OK to test permissions. Return True if access is allowed, False if 
not. See the Unix man page access(2) for more information. Availability: 
Macintosh, Unix, Windows.
Note: Using access() to check if a user is authorized to e.g. open a 
file before actually doing so using open() creates a security hole, 
because the user might exploit the short time interval between checking 
and opening the file to manipulate it.

I call that note a warning.

More information about the Python-list mailing list