@@ -78,6 +78,8 @@ def __init__(
7878 config_path = None ,
7979 check_server = True
8080 ):
81+ # Track if timeout is overridden
82+ self ._timeout_overridden = False
8183 # Initialize config with defaults
8284 self .config = copy .deepcopy (self .DEFAULT_CONFIG )
8385
@@ -97,7 +99,6 @@ def __init__(
9799
98100 # Configure logging based on config
99101 self ._configure_logging ()
100-
101102 if check_server :
102103 self ._test_server_connection ()
103104
@@ -106,6 +107,8 @@ def _set_config_params(self, params):
106107 for key , value in params .items ():
107108 if value is not None :
108109 self .config [key ] = value
110+ if key == 'timeout' :
111+ self ._timeout_overridden = True
109112
110113 def _handle_server_busy_retry (self , file_path , retry_func , * args , ** kwargs ):
111114 """Handle server busy (503) retry logic."""
@@ -240,6 +243,8 @@ def _load_config(self, path="./config.json"):
240243 # Update the default config with values from the file
241244 file_config = json .loads (config_json )
242245 self .config .update (file_config )
246+ if 'timeout' in file_config :
247+ self ._timeout_overridden = True
243248 temp_logger .info ("Configuration file loaded successfully" )
244249 except FileNotFoundError as e :
245250 # If config file doesn't exist, keep using default values
@@ -555,9 +560,13 @@ def process_pdf(
555560 if end and end > 0 :
556561 the_data ["end" ] = str (end )
557562
563+ # Only multiply timeout if consolidate_citations and not overridden
564+ base_timeout = self .config ['timeout' ]
565+ effective_timeout = base_timeout * 2 if consolidate_citations and not self ._timeout_overridden else base_timeout
566+
558567 res , status = self .post (
559568 url = the_url , files = files , data = the_data , headers = {"Accept" : "text/plain" },
560- timeout = self . config [ 'timeout' ]
569+ timeout = effective_timeout
561570 )
562571
563572 if status == 503 :
0 commit comments