Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6209

Re: File access denied after subprocess completion on Windows platform

From Claudiu Nicolaie CISMARU <claudiu@virtuamagic.com>
Organization virtuaMAGIC
Subject Re: File access denied after subprocess completion on Windows platform
Date 2011-05-25 11:20 +0300
References <mailman.2013.1306231878.9059.python-list@python.org> <201105242318.32306.claudiu@virtuamagic.com> <4DDCAD12.4050203@timgolden.me.uk>
Newsgroups comp.lang.python
Message-ID <mailman.2058.1306311652.9059.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

> 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@virtuamagic.com, claudiu.cismaru@gmail.com

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

File access denied after subprocess completion on Windows platform Claudiu Nicolaie CISMARU <claudiu@virtuamagic.com> - 2011-05-24 13:01 +0300
  Re: File access denied after subprocess completion on Windows platform Claudiu Nicolaie CISMARU <claudiu@virtuamagic.com> - 2011-05-24 20:17 +0300
  Re: File access denied after subprocess completion on Windows platform Claudiu Nicolaie CISMARU <claudiu@virtuamagic.com> - 2011-05-24 23:18 +0300
  Re: File access denied after subprocess completion on Windows platform Terry Reedy <tjreedy@udel.edu> - 2011-05-24 18:03 -0400
  Re: File access denied after subprocess completion on Windows platform Tim Golden <mail@timgolden.me.uk> - 2011-05-25 08:17 +0100
  Re: File access denied after subprocess completion on Windows platform Claudiu Nicolaie CISMARU <claudiu@virtuamagic.com> - 2011-05-25 11:20 +0300

csiph-web