@@ -195,7 +195,9 @@ def _presolve(self, *args, **kwds):
195195
196196 def available (self , exception_flag = False ):
197197 """True if the solver is available"""
198- return self ._python_api_exists
198+ if not self ._python_api_exists :
199+ return False
200+ return self .start_sas_session () is not None
199201
200202 def _has_integer_variables (self ):
201203 """True if the problem has integer variables."""
@@ -285,12 +287,7 @@ def __init__(self, **kwds):
285287
286288 # Store other options for the SAS session
287289 self ._session_options = kwds
288-
289- # Create the session
290- try :
291- self ._sas_session = self ._sas .SASsession (** self ._session_options )
292- except :
293- self ._sas_session = None
290+ self ._sas_session = None
294291
295292 def __del__ (self ):
296293 # Close the session, if we created one
@@ -314,6 +311,15 @@ def _create_statement_str(self, statement):
314311 def sas_version (self ):
315312 return self ._sasver
316313
314+ def start_sas_session (self ):
315+ if self ._sas_session is None :
316+ # Create (and cache) the session
317+ try :
318+ self ._sas_session = self ._sas .SASsession (** self ._session_options )
319+ except :
320+ pass
321+ return self ._sas_session
322+
317323 def _apply_solver (self ):
318324 """ "Prepare the options and run the solver. Then store the data to be returned."""
319325 logger .debug ("Running SAS" )
@@ -374,10 +380,7 @@ def _apply_solver(self):
374380 sas_options = "option notes nonumber nodate nosource pagesize=max;"
375381
376382 # Get the current SAS session, submit the code and return the results
377- if not self ._sas_session :
378- sas = self ._sas_session = self ._sas .SASsession (** self ._session_options )
379- else :
380- sas = self ._sas_session
383+ sas = self .start_sas_session ()
381384
382385 # Find the version of 9.4 we are using
383386 self ._sasver = sas .sasver
@@ -585,19 +588,23 @@ def __init__(self, **kwds):
585588 self ._python_api_exists = True
586589
587590 self ._session_options = kwds
588-
589- # Create the session
590- try :
591- self ._sas_session = self ._sas .CAS (** self ._session_options )
592- except :
593- self ._sas_session = None
591+ self ._sas_session = None
594592
595593 def __del__ (self ):
596594 # Close the session, if we created one
597595 if self ._sas_session :
598596 self ._sas_session .close ()
599597 del self ._sas_session
600598
599+ def start_sas_session (self ):
600+ if self ._sas_session is None :
601+ # Create (and cache) the session
602+ try :
603+ self ._sas_session = self ._sas .CAS (** self ._session_options )
604+ except :
605+ pass
606+ return self ._sas_session
607+
601608 def _uploadMpsFile (self , s , unique ):
602609 # Declare a unique table name for the mps table
603610 mpsdata_table_name = "mps" + unique
0 commit comments