[Twisted-Python] Stoping a deferedList

tarjei tarjei at nu.no
Mon Jan 28 07:29:11 MST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I'm using the FtpClient to upload a set of files. I start the uploads
with the following code:


   def fileError(self, result):
        log.msg("Error has happened" + result.getErrorMessage())
        log.msg(result.trap(Exception))
        return result

    def endError(self, result):
        log.msg("End Error has happened")
        self.client.quit()
        self.client.transport.loseConnection()
        result.trap(Exception)

    def connectionMade(self,ftpClient):
        "Checks if there are more files to upload and uploads them."
        deffereds = []
        "We'll need the client to do a disconnect later"
        self.client = ftpClient
        " Create defereds for each of the different files to be uploaded"
        for upfile in self.ftpFiles:
            store, finish = ftpClient.storeFile(self._getPath(
upfile.get_name() ) )
            finish.addCallback(self.end).addErrback(self.fileError)
            store.addCallback(self.send_file, upfile
).addErrback(self.fileError)
            deffereds.append(store)
            deffereds.append(finish)
            self.numfiles += 1
        return
defer.gatherResults(deffereds).addCallback(self.success).addErrback(self.endError)


Now, if an error happens during the upload of one file, then I want to
stop the other files as well and close the connection. When I try to run
tests using the above code, trial reports that it still has open
connections.

The code works fine if user has access to save the files, it is the
error handling I want to get done right.

What should I do to ensure that all connections get closed when an error
happens?

kind regards,
Tarjei
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHnea3YVRKCnSvzfIRAh3RAJ9lrMzQBJOMtIo1qcuntbkZlX5HMACfZNS8
St7eOg43MC4mTR2Qh9XWAX4=
=aJCZ
-----END PGP SIGNATURE-----




More information about the Twisted-Python mailing list