Skip to content

Commit

Permalink
add keepalive option to IOM
Browse files Browse the repository at this point in the history
  • Loading branch information
tomweber-sas committed Apr 8, 2024
1 parent 84ace07 commit 3c50633
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion saspy/sasiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ def _endsas(self):
resp = req.read()
conn.close()

self._refthd.join(5)
self._refthd.join(1)

if self.sascfg.verbose:
logger.info("SAS server terminated for SESSION_ID="+self._session.get('id'))
Expand All @@ -835,6 +835,8 @@ def _endsas(self):
def _refresh_thread(self):
while True:
sleep(3000)
if self.pid is None:
return
self._refresh_token()

def _refresh_token(self):
Expand Down
26 changes: 26 additions & 0 deletions saspy/sasioiom.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import warnings
import io
import atexit
from threading import Thread

import logging
logger = logging.getLogger('saspy')
Expand Down Expand Up @@ -71,6 +72,10 @@ def __init__(self, session, **kwargs):
self.reconuri = cfg.get('reconuri', None)
self.logbufsz = cfg.get('logbufsz', None)
self.log4j = cfg.get('log4j', '2.12.4')
self.keep = cfg.get('keepalive', None)

if self.keep:
self.keep = int(self.keep)

try:
self.outopts = getattr(SAScfg, "SAS_output_options")
Expand Down Expand Up @@ -261,6 +266,13 @@ def __init__(self, session, **kwargs):
else:
self.logbufsz = inlogsz

inkeep = kwargs.get('keepalive', None)
if inkeep:
if lock and self.keep:
logger.warning("Parameter 'keepalive' passed to SAS_session was ignored due to configuration restriction.")
else:
self.keep = int(inkeep)

self._prompt = session._sb.sascfg._prompt

return
Expand Down Expand Up @@ -576,6 +588,11 @@ def _startsas(self):
if self.sascfg.verbose:
logger.info("SAS Connection established. Subprocess id is "+str(pid)+"\n")

if self.sascfg.keep:
self._keep = Thread(target=self._keepalive_thread, args=())
self._keep.daemon = True
self._keep.start()

atexit.register(self._endsas)

return self.pid
Expand Down Expand Up @@ -636,6 +653,9 @@ def _endsas(self):
except:
pass

if self.sascfg.keep:
self._keep.join(1)

try: # Mac OS Python has bugs with this call
self.stdin[0].shutdown(socks.SHUT_RDWR)
except:
Expand Down Expand Up @@ -663,6 +683,12 @@ def _endsas(self):
self._sb.SASpid = None
return

def _keepalive_thread(self):
while True:
sleep(self.sascfg.keep * 100)
if self.pid is None:
return
self.submit('', results='text')

"""
def _getlog(self, wait=5, jobid=None):
Expand Down

0 comments on commit 3c50633

Please sign in to comment.