[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] How to close audio file?



On Fri, Mar 23, 2012 at 3:41 PM, James Paige <Bob@xxxxxxxxxxxxxxxxxxx> wrote:
> Maybe my memory is fuzzy from so much time spent on Linux, but I thought
> Windows only locked files that you have open for writing. Shouldn't it
> not be locking a file that is only open for read?

Nope, that's not how Windows works:

>>> open("testremove","wb").close()
>>> f=open("testremove","rb")
>>> os.remove("testremove")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
WindowsError: [Error 32] The process cannot access the file because it
is being used by another process: 'testremove'
>>> f.close()
>>> os.remove("testremove")
>>>

If you directly use the Windows CreateFile function, I think you can
set dwShareMode to specify that the file can be deleted, but I don't
think you can achieve that with the regular Python open() function or
anything in os.