[PyQt] problem with threaded ftp and QFtp.close()

Phil Thompson phil at riverbankcomputing.com
Tue Mar 19 09:24:54 GMT 2013

On Mon, 18 Mar 2013 19:42:00 -0700, Brian Knudson <briank at pipelinefx.com>
> I'm running multiple instances of QFtp in multiple QThreads so I can
> download in multiple streams at the same time.
> If I leave out ftp.close() (where ftp is a QFtp), all my threads
> emit a finished signal.  This is great, but it leaves the ftp user
> into my ftp server, eventually hitting a max_connections limit (on the
> server), which prevents the remaining ftp transfers from starting.  When
> the program exits, the connections do close.
> If I follow my ftp.get(...) (there is one per thread) with an
> I can see the connections closing on my ftp server, I never hit
> max_connections on the ftp server, every download completes, but the
> threads never emit a "finished" signal (likely because the QFtp never
> a "done" signal), so the rest of the application doesn't behave
> I haven't made an example, as an example would require a fair amount of
> effort.  I'm wondering if anyone else has seen this or would have an
> of special handling required for the .close() method of QFtps in
> Maybe it using ftp.close() implies a "done" signal & one must be
> emitted by catching the close in the ftp.commandFinished signal handler?
> At the end of the day, the QThread's run method looks something like:
> self.ftp = QtNetwork.QFtp()
> self.ftp.commandFinished.connect(self.ftpCommandFinished)
> self.ftp.dataTransferProgress.connect(self.ftpDataTransferProgress)
> self.ftp.connectToHost(url.host(), url.port(21))
> self.ftp.login(url.userName(), url.password())
> self.ftp.get(url.path(), self.out_file)
> self.ftp.close()

QFtp is an asynchronous implementation so you don't need QThreads to
download multiple streams at the same time.


More information about the PyQt mailing list