python - "file being used by another process" error message -
Yes, there are many other questions on this subject, I have seen the reactions but I have not seen any such useful solution gives.
I have a problem in its simplest form:
import os, time hfile = "status. Html" hf = open (hfile, "w") hf.write (Str (buf)) hf.close time.sleep (2) # Allow time to capture os.system (hfile) # File in the default browser
I get this error message : "The process can not access the file because it is being used by another process".
No other process is using it, because I can access it without error from another program, even if I run os.system (file)
There is no point in using unlocker from the Python console
, as soon as I leave the program, I can open the html file in the browser, no complaints from the system.
This is not releasing the 'closed' file properly.
I run programs like this out of Pearl all the time, leaving a delay of 1 or 2 seconds without any problem.
Any suggestions?
You are not calling pass ()
. Must be:
import OS, time hfile = "condition .htm" hf = open (hfile, "w") hf.write (str (buf)) hf.close () # Note that parens time.sleep (2) # time to hold it os.system (hfile) # Run the html file in the default browser
However to avoid problems like this You must use the Reference Manager:
imported OS, with hfile = "positions.htm" open (hfile, 'w') as hf: hf.write (str (Buf) os.system (Hfile) # Run the html file in the default browser
References The Bh Manager will automatically be able to close the file.
Comments
Post a Comment