@@ -958,15 +958,14 @@ def _getlog(self, jobid=None, loglines=False):
958958 else :
959959 uri = self ._uri_log
960960
961+ conn = self .sascfg .HTTPConn ; conn .connect ()
961962 while True :
962963 # GET Log
963- conn = self .sascfg .HTTPConn ; conn .connect ()
964964 headers = {"Accept" :"application/vnd.sas.collection+json" , "Authorization" :"Bearer " + self .sascfg ._token }
965965 conn .request ('GET' , uri + "?start=" + str (start )+ "&limit=" + str (start + 1000 ), headers = headers )
966966 req = conn .getresponse ()
967967 status = req .status
968968 resp = req .read ()
969- conn .close ()
970969
971970 try :
972971 js = json .loads (resp .decode (self .sascfg .encoding ))
@@ -981,6 +980,7 @@ def _getlog(self, jobid=None, loglines=False):
981980
982981 logl += log
983982
983+ conn .close ()
984984 for line in logl :
985985 logr += line .get ('line' )+ '\n '
986986
@@ -1060,14 +1060,13 @@ def _getlsttxt(self, jobid=None):
10601060 else :
10611061 uri = self ._uri_lst
10621062
1063+ conn = self .sascfg .HTTPConn ; conn .connect ()
10631064 while True :
1064- conn = self .sascfg .HTTPConn ; conn .connect ()
10651065 headers = {"Accept" :"application/vnd.sas.collection+json" , "Authorization" :"Bearer " + self .sascfg ._token }
10661066 conn .request ('GET' , uri + "?start=" + str (start )+ "&limit=" + str (start + 1000 ), headers = headers )
10671067 req = conn .getresponse ()
10681068 status = req .status
10691069 resp = req .read ()
1070- conn .close ()
10711070
10721071 try :
10731072 js = json .loads (resp .decode (self .sascfg .encoding ))
@@ -1083,6 +1082,7 @@ def _getlsttxt(self, jobid=None):
10831082 for line in lst :
10841083 lstr += line .get ('line' )+ '\n '
10851084
1085+ conn .close ()
10861086 return lstr .replace (chr (12 ), chr (10 ))
10871087
10881088 def _asubmit (self , code , results = "html" ):
@@ -1248,15 +1248,14 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
12481248 done = True
12491249
12501250 headers = {"Accept" :"text/plain" , "Authorization" :"Bearer " + self .sascfg ._token , "If-None-Match" : Etag }
1251+ conn .connect ()
12511252 while not done :
12521253 try :
12531254 while True :
12541255 # GET Status for JOB
1255- conn .connect ()
12561256 conn .request ('GET' , uri + "?wait=" + str (delay ), headers = headers )
12571257 req = conn .getresponse ()
12581258 resp = req .read ()
1259- conn .close ()
12601259 if resp not in [b'running' , b'pending' , b'' ]:
12611260 done = True
12621261 break
@@ -1305,6 +1304,7 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs)
13051304 if excpcnt < 0 :
13061305 raise
13071306
1307+ conn .close ()
13081308 logs = self ._getlog (jobid , lines )
13091309
13101310 if not lines :
0 commit comments