channel.downloadToFile

Hello,

I got a problem with httpClient. I took my code from the manual, but I used downloadToFile.

After downloading file from a http server, they are locked by a processus, and when I try to execute an .exe, I got an error message, because the file is locked by another processus.

At my mind, when I download the file via the channel, it locks the file, and not free it. I don’t know how to close the channel, or what I need to free my file:

	if self.http==None:
							self.http = HTTPClient()
							self.channel = self.http.makeChannel(True)
							self.channel.setPersistentConnection(False)
							self.channel.beginGetDocument(DocumentSpec('http://localhost/updater/ressources/' + self.files[self.iterFile].replace("\\","/")))
							ff=Filename(self.convDirectory + "/" + self.files[self.iterFile].replace("\\","/"))
							self.createTree(self.directory+self.files[self.iterFile])
							self.channel.downloadToFile(ff)

if not self.channel.isDownloadComplete():
									print "Error downloading file." + self.channel.getStatusString() + str(self.channel.getStatusCode())
									return task.done
								elif self.channel.isDownloadComplete():
									fileHandle = open ( "./update.txt", 'a+' ) 
									fileHandle.write("file="+str(self.files[self.iterFile])+ "\n")
									fileHandle.close()
									self.iterFile+=1

I think on the case of isDownloadComplete, I have to do something to close the channel.

Thank you

Note that you are using the non-blocking beginGetDocument() instead of the blocking getDocument() call. This means you have to keep calling self.channel.run() until it returns false, and only then should you check isDownloadComplete(). It’s hard to tell whether this is what you’re doing in this code snippet.

If you are doing this, I think that the file will be closed correctly after run() returns false.

Or, you can call getDocument() instead, and then when you call downloadToFile() it will download the file completely (and close it) before it returns, which is much simpler to deal with. But it does mean you will lock up all the tasks while it downloads.

David

Thank for reply.

I replace beginGetDocument by getDocument, but I got the same behaviour.

The file is locked by a process.

If I restart my apps, and because the file exists already, it is not downloaded by my application, I can launch the exe without trouble.