mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
calibredb: Add a timeout option to control the timeout when connecting to the calibre server
This commit is contained in:
parent
ae2582659c
commit
07aabb488b
@ -84,6 +84,13 @@ def get_parser(usage):
|
|||||||
' for your shell.').format(
|
' for your shell.').format(
|
||||||
'<stdin>', '<f:C:/path/to/file>' if iswindows else '<f:/path/to/file>')
|
'<stdin>', '<f:C:/path/to/file>' if iswindows else '<f:/path/to/file>')
|
||||||
)
|
)
|
||||||
|
go.add_option(
|
||||||
|
'--timeout',
|
||||||
|
type=float,
|
||||||
|
default=120,
|
||||||
|
help=_('The timeout, in seconds when connecting to a calibre library over the network. The default is'
|
||||||
|
' two minutes.')
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -122,6 +129,7 @@ class DBCtx(object):
|
|||||||
|
|
||||||
def __init__(self, opts):
|
def __init__(self, opts):
|
||||||
self.library_path = opts.library_path or prefs['library_path']
|
self.library_path = opts.library_path or prefs['library_path']
|
||||||
|
self.timeout = opts.timeout
|
||||||
self.url = None
|
self.url = None
|
||||||
if self.library_path is None:
|
if self.library_path is None:
|
||||||
raise SystemExit(
|
raise SystemExit(
|
||||||
@ -194,7 +202,7 @@ class DBCtx(object):
|
|||||||
rq = Request(url, data=msgpack_dumps(args),
|
rq = Request(url, data=msgpack_dumps(args),
|
||||||
headers={'Accept': MSGPACK_MIME, 'Content-Type': MSGPACK_MIME})
|
headers={'Accept': MSGPACK_MIME, 'Content-Type': MSGPACK_MIME})
|
||||||
try:
|
try:
|
||||||
res = self.br.open_novisit(rq)
|
res = self.br.open_novisit(rq, timeout=self.timeout)
|
||||||
ans = msgpack_loads(res.read())
|
ans = msgpack_loads(res.read())
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
self.interpret_http_error(err)
|
self.interpret_http_error(err)
|
||||||
@ -209,7 +217,7 @@ class DBCtx(object):
|
|||||||
from mechanize import HTTPError
|
from mechanize import HTTPError
|
||||||
url = self.url + '/ajax/library-info'
|
url = self.url + '/ajax/library-info'
|
||||||
try:
|
try:
|
||||||
res = self.br.open_novisit(url)
|
res = self.br.open_novisit(url, timeout=self.timeout)
|
||||||
ans = json.loads(res.read())
|
ans = json.loads(res.read())
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
self.interpret_http_error(err)
|
self.interpret_http_error(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user