@@ -139,6 +139,10 @@ def _conf_or_default(key, value):
139
139
parser .add_argument ('--hosts' , type = str , nargs = '*' ,
140
140
default = _conf_or_default ('hosts' , ['localhost:4200' ]),
141
141
help = 'connect to HOSTS.' , metavar = 'HOSTS' )
142
+ parser .add_argument ('--timeout' , type = str , metavar = 'TIMEOUT' ,
143
+ help = 'Configure "connect,read" network timeout values different than "5,infinite" seconds.'
144
+ 'Obtains either a scalar integer or float value used as connect timeout,'
145
+ 'or a tuple of connect- vs. read-timeout, separated by a comma.' , default = "5" )
142
146
parser .add_argument (
143
147
'--verify-ssl' ,
144
148
choices = (True , False ),
@@ -620,6 +624,23 @@ def save_and_exit():
620
624
621
625
def _create_shell (crate_hosts , error_trace , output_writer , is_tty , args ,
622
626
timeout = None , password = None ):
627
+
628
+ # Explicit "timeout" function argument takes precedence.
629
+ if timeout is not None :
630
+ if isinstance (timeout , tuple ):
631
+ connect_timeout , read_timeout = timeout [0 ], timeout [1 ]
632
+ timeout = urllib3 .Timeout (connect = float (connect_timeout ), read = float (read_timeout ))
633
+ else :
634
+ timeout = urllib3 .Timeout (connect = float (timeout ), read = None )
635
+
636
+ # Probe `--timeout`` command line argument second.
637
+ elif args .timeout is not None :
638
+ if "," in args .timeout :
639
+ connect_timeout , read_timeout = args .timeout .split ("," )
640
+ timeout = urllib3 .Timeout (connect = float (connect_timeout ), read = float (read_timeout ))
641
+ else :
642
+ timeout = urllib3 .Timeout (connect = float (args .timeout ), read = None )
643
+
623
644
return CrateShell (crate_hosts ,
624
645
error_trace = error_trace ,
625
646
output_writer = output_writer ,
0 commit comments