mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-19 18:31:24 +02:00
global timeout
This commit is contained in:
parent
0583c7910c
commit
7152ec2e1a
@ -1,6 +1,7 @@
|
|||||||
#coding: utf-8
|
#coding: utf-8
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import socket
|
||||||
import threading
|
import threading
|
||||||
import Queue
|
import Queue
|
||||||
import requests
|
import requests
|
||||||
@ -8,6 +9,11 @@ from urlparse import urlparse
|
|||||||
from hentai.logger import logger
|
from hentai.logger import logger
|
||||||
|
|
||||||
|
|
||||||
|
# global timeout
|
||||||
|
timeout = 30
|
||||||
|
socket.setdefaulttimeout(timeout)
|
||||||
|
|
||||||
|
|
||||||
class Downloader(object):
|
class Downloader(object):
|
||||||
_instance = None
|
_instance = None
|
||||||
|
|
||||||
@ -34,7 +40,7 @@ class Downloader(object):
|
|||||||
filename = filename if filename else os.path.basename(urlparse(url).path)
|
filename = filename if filename else os.path.basename(urlparse(url).path)
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(folder, filename), "wb") as f:
|
with open(os.path.join(folder, filename), "wb") as f:
|
||||||
response = requests.get(url, stream=True)
|
response = requests.get(url, stream=True, timeout=10)
|
||||||
length = response.headers.get('content-length')
|
length = response.headers.get('content-length')
|
||||||
if length is None:
|
if length is None:
|
||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user