Skip to content

Commit

Permalink
manubot#337 connect command timeout with execution timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
xihh87 committed Jul 28, 2022
1 parent 3e1b783 commit 271e39e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
9 changes: 8 additions & 1 deletion manubot/cite/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ class Citations:
# `sort_csl_items=False` retains order of input_ids in get_csl_items.
# (input_ids with the same standard_id will still be deduplicated).
sort_csl_items: bool = True
# timeout for requests
timeout_seconds: tp.Union[tuple, int, float, None] = (3, 15)

def __post_init__(self):
input_ids = list(dict.fromkeys(self.input_ids)) # deduplicate
self.citekeys = [
CiteKey(x, aliases=self.aliases, infer_prefix=self.infer_citekey_prefixes)
CiteKey(
x,
aliases=self.aliases,
infer_prefix=self.infer_citekey_prefixes,
timeout_seconds=self.timeout_seconds,
)
for x in input_ids
]

Expand Down
4 changes: 3 additions & 1 deletion manubot/cite/citekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CiteKey:
"""Mapping from input identifier to aliases"""
infer_prefix: bool = True
"""Whether to infer the citekey's prefix when a prefix is missing or unhandled"""
timeout_seconds: tp.Union[tuple, int, float, None] = (3, 12)
"""The time to wait when making requests"""

def __post_init__(self):
self.check_input_id(self.input_id)
Expand Down Expand Up @@ -208,7 +210,7 @@ def __repr__(self):
def csl_item(self):
from .csl_item import CSL_Item

csl_item = self.handler.get_csl_item(self)
csl_item = self.handler.get_csl_item(self, self.timeout_seconds)
if not isinstance(csl_item, CSL_Item):
csl_item = CSL_Item(csl_item)
csl_item.set_id(self.standard_id)
Expand Down
3 changes: 1 addition & 2 deletions manubot/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def parse_arguments():
"-t",
"--timeout",
dest="timeout_seconds",
default="3",
type=int,
default=(3, 15),
help="timeout for web requests in seconds",
)
args = parser.parse_args()
Expand Down

0 comments on commit 271e39e

Please sign in to comment.