ftp design question
Steve Holden
steve at holdenweb.com
Sun Dec 28 23:31:42 EST 2008
nemo wrote:
> Hi,all.
> I'm on a toy ftp project and I want it to be convinient for the user
> to cancel an undergoing downloading while continue others. The
> following code explains:
> for file in download_files:
> self.ftp.retrbinary('RETR '+file, fileHandler)
> Thers seems not a solid way to cancel this transfer and I considered
> thread or process but I can't handle this correctly.
> Thread: I can't kill the thread in another thread, so...
> Process: There seems something wrong(raise an EOFError exception) when
> I use Process(target = download_fun, args = (dir,)) for each
> downloading after connection built.
> Some suggestions?
How about
for file in download_files:
try:
self.ftp.retrbinary('RETR %s' % file, fileHandler)
except KeyboardInterrupt:
print file, "transfer abandoned"
Then you can cancel a single file transfer with Ctrl/C.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list