I/O error 13 Permission denied -Cannot access file as it is used by another process.

Tim Golden mail at timgolden.me.uk
Thu Aug 28 10:13:46 CEST 2008

aditya shukla wrote:
> Hello folks,
> I am creating a python script[windows vista and python2.5] which 
> accesses another program(prog2).I my python script i am creating a 
> temporary file and i write the output of prog2
> in this temporary file.
> temp = 
> tempfile.NamedTemporaryFile(suffix='_suffix',prefix='prefix_',dir='C:\\Python25') 
> - #this how create the temporary file ( i am not closing the temporary 
> file).This works fine

Why on earth are you *specifying* c:\python25 as the
directory for this file? It's automatically created
in your user-specific temp directory which has specific
permissions and is (obviously) specific to that user.
You may -- depending on your needs -- also not need the
suffix & prefix.

ie, unless you have some specific need in mind, just use:

temp = tempfile.NamedTemporaryFile ()

> x= os.path.split(tn)
>  y=x[1]
> Now  i search for the file and then try to read this file so that i can 
> perform some calculations.
> This step causes the problem
> file=open(find_file,"rb") # find_file is the object returned after 
> searching the file
> error mesage:
> the process cannot access the file as another process because it is 
> being used by another program.(prog2 in this case)
> i/o error 13 permission denied

The main stumbling block here is that you're not posting
code you're running, but fragments of code which may or
may not exist in your source. What is tn? What have x
and y to do with anything? What is find_file? And so on.

As far as I can tell you're trying to create a temporary
file, pass its name to another process which writes to
it. You then, in the first process, read the results of
the second process. Is that right?

At the very least, please cut-and-paste a session from 
the console which is running the program so that the traceback
is clear.


More information about the Python-list mailing list