2525from irods .exception import (NetworkException , NotImplementedInIRODSServer )
2626from irods .password_obfuscation import decode
2727from irods import NATIVE_AUTH_SCHEME , PAM_AUTH_SCHEMES
28- from . import DEFAULT_CONNECTION_TIMEOUT
28+ from . import ( DEFAULT_CONNECTION_TIMEOUT , MAXIMUM_CONNECTION_TIMEOUT )
2929
3030_fds = None
3131_fds_lock = threading .Lock ()
3232_sessions = None
3333_sessions_lock = threading .Lock ()
3434
35-
3635def _cleanup_remaining_sessions ():
3736 for fd in list (_fds .keys ()):
3837 if not fd .closed :
@@ -59,6 +58,7 @@ def _weakly_reference(ses):
5958
6059class NonAnonymousLoginWithoutPassword (RuntimeError ): pass
6160
61+
6262class iRODSSession (object ):
6363
6464 def library_features (self ):
@@ -141,7 +141,8 @@ def __init__(self, configure = True, auto_cleanup = True, **kwargs):
141141 self ._env_file = ''
142142 self ._auth_file = ''
143143 self .do_configure = (kwargs if configure else {})
144- self ._cached_connection_timeout = kwargs .pop ('connection_timeout' , DEFAULT_CONNECTION_TIMEOUT )
144+ self ._cached_connection_timeout = None
145+ self .connection_timeout = kwargs .pop ('connection_timeout' , DEFAULT_CONNECTION_TIMEOUT )
145146 self .__configured = None
146147 if configure :
147148 self .__configured = self .configure (** kwargs )
@@ -366,16 +367,22 @@ def connection_timeout(self, seconds):
366367 exc = ValueError ("Setting an iRODS connection_timeout to 0 seconds would make it non-blocking." )
367368 raise exc
368369 elif isinstance (seconds , Number ):
369- if seconds < 0 or str (seconds ) == 'nan' or str (abs (seconds )) == 'inf' :
370- exc = ValueError ("The iRODS connection_timeout may not be assigned a negative or otherwise rogue value (eg: NaN, Inf)." )
370+ # Note: We can handle infinities because -Inf < 0 and Inf > MAXIMUM_CONNECTION_TIMEOUT.
371+ if seconds < 0 or str (seconds ) == 'nan' :
372+ exc = ValueError ("The iRODS connection_timeout may not be assigned a negative, out-of-bounds, or otherwise rogue value (eg: NaN, -Inf)." )
371373 raise exc
374+ elif seconds > MAXIMUM_CONNECTION_TIMEOUT :
375+ logging .getLogger (__name__ ).warning ('Hard limiting connection timeout of %g to the maximum allowable value of %g' ,
376+ seconds , MAXIMUM_CONNECTION_TIMEOUT )
377+ seconds = MAXIMUM_CONNECTION_TIMEOUT
372378 elif seconds is None :
373379 pass
374380 else :
375381 exc = ValueError ("The iRODS connection_timeout must be assigned a positive int, positive float, or None." )
376382 raise exc
377383 self ._cached_connection_timeout = seconds
378- self .pool .connection_timeout = seconds
384+ if self .pool :
385+ self .pool .connection_timeout = seconds
379386
380387 @staticmethod
381388 def get_irods_password_file ():
0 commit comments