How to unlock urllib files ?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
BigBellyBilly Offline
Skilled Python Coder
Posts: 900
Joined: Feb 2005
Reputation: 2
Location: UK
Post: #1
I've come across a situation where if a urllib.retrieve download is cancelled (from a reporthook iscancelled check) the partially downloaded file can't be os.remove(file_name) as it throws an OSError errno 13 'permission denied' exception.

I've tried a delay loop to retry the delete but no matter what the wait period is it remains locked.

Could it be that the file is readonly until download completion, as it can be deleted if not cancelled ?

Any ideas?

Thanks
BBB

My Addons (myTV, T3CH Upgrader, DVDProfiler, BBCPodRadio, Comics, Football, GoogleReader, reeplay.it, Metacritic, Phonebin, FileViewer,SVN Repo Installer (contributor)) available at Box.net
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,910
Joined: Dec 2004
Reputation: 18
Post: #2
did you try a loop? it seems to always fail the first time you try and remove it.

this is what i use and it works fine.

PHP Code:
except:
            
urllib.urlcleanup()
            
remove_tries 3
            
while remove_tries and os.path.isfilefilepath ):
                try:
                    
os.removefilepath )
                
except:
                    
remove_tries -= 1
                    xbmc
.sleep1000 

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
BigBellyBilly Offline
Skilled Python Coder
Posts: 900
Joined: Feb 2005
Reputation: 2
Location: UK
Post: #3
I currently have this:

Code:
for count in range(5):
    try:
        os.remove( file_name )
        break
    except OSError:
        time.sleep(0.2)
    except:
        break

In the code before this is called I do also do a urllib.urlcleanup()

Notice I use time.sleep and not xbmc.sleep Which is preferred? Maybe the longer xbmc sleep makes the difference ?

I'll try your code and see what happens.
cheers
BBB

My Addons (myTV, T3CH Upgrader, DVDProfiler, BBCPodRadio, Comics, Football, GoogleReader, reeplay.it, Metacritic, Phonebin, FileViewer,SVN Repo Installer (contributor)) available at Box.net
find quote