process cannot access the file because it is being used by other process

shanti bhushan ershantibhushan at gmail.com
Mon Jun 21 04:23:32 EDT 2010


Hi,

i am using below code ,it works fine on ordinary python 26 ,but when i
use this script in my python testing tool it gives me message "process
cannot access the file because it is being used by other process" for
the second time invoking of mongoose server.
Please help me in handling this exception.

def invoke_server2():
    file = open("mongoose-2.8.exe", "r")
    try:
        proc = subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
\372\pythonweb\mongoose-2.8.exe -root D:\New1\ >YourOutput.txt"')
    except OSError:
        print "os error"
        file.close()
        sys.exc_clear()
        os.remove("mongoose-2.8.exe")

def invoke_server3():
    file = open("mongoose-2.8.exe", "r")
    try:
        proc = subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
\372\pythonweb\mongoose-2.8.exe -root D:\New2\ >YourOutput.txt"')
    except OSError:
        print "os error"
        file.close()
        sys.exc_clear()
        os.remove("mongoose-2.8.exe")


def kill_server():
    killret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c
"taskkill /F /IM mongoose-2.8.exe >YourOutput1.txt"')
    print killret


invoke_server1()
time.sleep(5)
kill_server()
time.sleep(5)
invoke_server2()
time.sleep(5)
kill_server()
time.sleep(5)
invoke_server3()
time.sleep(5)
kill_server()



More information about the Python-list mailing list