Cadair / parfive

An asyncio based parallel file downloader for Python 3.8+

Home Page:https://parfive.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

keyboard interrupt does not kill the download loop cleanly

Cadair opened this issue · comments

In a jupyter notebook, because the loop is running in a threadpool, this means that the download isn't cancelled at all. In a regular session it causes all the coroutines to fail with a KeyboardInterrupt exception.

Thoughts on implementing this:

  • We can react to the signal with event_loop.add_signal_handler.
  • The event handler should cleanly terminate all pending and all running task, by calling Task.cancel (addressing #61 should mean we always have a Task object to cancel).
  • This should involve removing any part-finished files from disk so that there aren't corrupt files left lying around.
  • When a Task is cancelled it throws a CancelledError. This would need to be caught in _get_http and _get_ftp to cleanly terminate the task.