[signals] implement stopping the current download with Ctrl+C (#1861)
{
"signals-actions": {
"SIGINT": "download:fail"
}
}
This commit is contained in:
@@ -12,8 +12,9 @@ import time
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
from requests.exceptions import RequestException, ConnectionError, Timeout
|
from requests.exceptions import RequestException, ConnectionError, Timeout
|
||||||
from .common import DownloaderBase
|
from .common import DownloaderBase
|
||||||
from .. import text, util, output
|
from .. import text, util, output, exception
|
||||||
from ssl import SSLError
|
from ssl import SSLError
|
||||||
|
FLAGS = util.FLAGS
|
||||||
|
|
||||||
|
|
||||||
class HttpDownloader(DownloaderBase):
|
class HttpDownloader(DownloaderBase):
|
||||||
@@ -336,6 +337,12 @@ class HttpDownloader(DownloaderBase):
|
|||||||
msg = str(exc)
|
msg = str(exc)
|
||||||
output.stderr_write("\n")
|
output.stderr_write("\n")
|
||||||
continue
|
continue
|
||||||
|
except exception.StopExtraction:
|
||||||
|
response.close()
|
||||||
|
return False
|
||||||
|
except exception.ControlException:
|
||||||
|
response.close()
|
||||||
|
raise
|
||||||
|
|
||||||
# check file size
|
# check file size
|
||||||
if size and fp.tell() < size:
|
if size and fp.tell() < size:
|
||||||
@@ -373,6 +380,9 @@ class HttpDownloader(DownloaderBase):
|
|||||||
for data in content:
|
for data in content:
|
||||||
write(data)
|
write(data)
|
||||||
|
|
||||||
|
if FLAGS.DOWNLOAD is not None:
|
||||||
|
FLAGS.process("DOWNLOAD")
|
||||||
|
|
||||||
def _receive_rate(self, fp, content, bytes_total, bytes_start):
|
def _receive_rate(self, fp, content, bytes_total, bytes_start):
|
||||||
rate = self.rate() if self.rate else None
|
rate = self.rate() if self.rate else None
|
||||||
write = fp.write
|
write = fp.write
|
||||||
@@ -387,6 +397,9 @@ class HttpDownloader(DownloaderBase):
|
|||||||
|
|
||||||
write(data)
|
write(data)
|
||||||
|
|
||||||
|
if FLAGS.DOWNLOAD is not None:
|
||||||
|
FLAGS.process("DOWNLOAD")
|
||||||
|
|
||||||
if progress is not None:
|
if progress is not None:
|
||||||
if time_elapsed > progress:
|
if time_elapsed > progress:
|
||||||
self.out.progress(
|
self.out.progress(
|
||||||
|
|||||||
Reference in New Issue
Block a user