python - Error on doing shutil.rmtree -


in python code copying installer temp , installing , want delete temp copy. using "shutil.rmtree" function remove installer copy in temp. sometime getting error "[error 32] process cannot access file because being used process"

how can avoid ? have way check directory not used other program ? if yes can check availability of directory till other process leaves control , delete ?

please me sample codes ! pretty new python.

copy_dst = tempfile.mkdtemp()  if success:     success = robocopy_file_or_folder(installer_location, copy_dst)  local_path_to_setup = os.path.join(copy_dst, app_folder, 'setup.exe')  if success:     success, response_text = install_product(local_path_to_setup, success, response_text) try:     if success:         shutil.rmtree(copy_dst, ignore_errors = false, onerror=handle_remove_readonly) except oserror e:     log("      %s\n      delete installer local copy @ \"%s\" failed.\n" % (e, copy_dst))     success = false 

this code !! , "install_product()" install product calling setup.exe in command.robocopy_file_or_folder () -- copy files.

def handle_remove_readonly(func, path, exc): """ changes access mode of specified folder remove read_only """ exc_value = exc[1] if func in (os.rmdir, os.remove) , exc_value.errno == errno.eacces:     os.chmod(path, stat.s_irwxu| stat.s_irwxg| stat.s_irwxo) # 0777     func(path) else:     raise 

"install_product()" install product calling setup.exe in command.robocopy_file_or_folder() – copy files.

wait installation finish , setup.exe exit before trying remove directory.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -