File access denied after subprocess completion on Windows platform
Claudiu Nicolaie CISMARU
claudiu at virtuamagic.com
Wed May 25 04:20:45 EDT 2011
> There used to be a problem with subprocess fds being held by
> a traceback. IIRC, the problem could be triggered by having
> an except clause around a subprocess call within which something
> attempted to, eg,
> remove one of the affected files.
I have no subprocess call.. in this last issue. And I didn't triggered
one (disabled the Button that runs the subprocess).
try:
for line in t.splitlines():
[...]
ret = self.downloadFileToDisk(filename, do_rename)
if not ret:
print "DEBUG: Problema la download"
raise Exception()
(1) except Exception as inst:
print type(inst)
print inst.args
self.updateText.emit("EROARE: Eroare la descarcare")
self.updateStatusBar.emit("EROARE: Eroare la descaracare
fisiere")
return
Where downloadFileToDisk():
def downloadFileToDisk(self, filename, final_rename=True):
dfilename = os.path.join(saveBasePATH, filename)
sfilename = dfilename + ".part"
dfolder = os.path.dirname(sfilename)
if dfolder != "":
if not os.path.isdir(dfolder):
os.makedirs(dfolder)
try:
fp = open(sfilename, "wb")
except:
return False
curl = pycurl.Curl()
curl.setopt(pycurl.URL, baseUpdateURL + "/client/" + filename)
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
curl.setopt(pycurl.NOPROGRESS, 0)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.PROGRESSFUNCTION, self.updateFileProgress)
curl.setopt(pycurl.WRITEDATA, fp)
curl.setopt(pycurl.BUFFERSIZE, 4194304)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.perform()
retcode = curl.getinfo(pycurl.HTTP_CODE)
curl.close()
fp.close()
if retcode != 200:
(2) os.unlink(sfilename)
return False
self.msleep(10)
if final_rename:
os.rename(sfilename, dfilename)
return True
Without self.msleep(10), (1) catches WindowsError: file access ... blah
blah. Maybe at (2) can be an access violation, but it wasn't triggered
yet in tests. I will move the sleep after fp.close(). Yes, I know that
what it've done with raise Exception() is UGLY, since this program it's
more a quick hack solution to a problem :). Anyway the Exception that is
catched is not rised by my code (it's a WindowsError).
> I'm sorry if that's a bit
> of a woolly description but if you think this might be
> biting you I'll dive in and look at the code. What version
> of Python are you using?
Last 2.7.x. Well, if os.rename is instead a subprocess call, then it's
subprocess based. I'm new to Python but 99% I think it's a system call
:)
> (That said, the fact that the behaviour varies between faster
> and slower computers makes that cause unlikely. Maybe we're
> back to looking at virus checkers and the like...)
On that virtual machine there is no virus checker. On the faster machine
I disabled and closed the antivirus.
--
Claudiu Nicolaie CISMARU
GNU GPG Key: http://claudiu.targujiu.net/key.gpg
T: +40 755 135455
E: claudiu at virtuamagic.com, claudiu.cismaru at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/python-list/attachments/20110525/a59b38bc/attachment-0001.sig>
More information about the Python-list
mailing list