0

I am constructing a class where I will encapsulate the saspy lib. What I want to develop now is a method to check if the SAS connection still alive, so, if not, I call it to reconnect.

I am looking for a magic method that is executed every time my instance is accessed anytime. Is there any? I am really new on classes construction.

class Sas_session:
    def __init__(self) -> None:
        self.iomhost: str = sasanl.host # type: ignore
        self.iomport: int = sasanl.port # type: ignore
        self.appserver: str = sasanl.appserver # type: ignore
        self.omruser: str = "" # type: ignore
        self.authkey: str = "" # type: ignore
        self.cfgname: str = "iomwin" # type: ignore
        self.timeout: int = 30 # type: ignore
        self.cfgfile = str(Path(__file__).parent / "ConexaoSAS.py")
        self.conectar()
          
    def conectar(self):
        self.session = saspy.SASsession(
            cfgname = self.cfgname,  # type: ignore
            cfgfile = self.cfgfile,  # type: ignore
            omruser = self.omruser,  # type: ignore
            iomhost = self.iomhost,  # type: ignore
            iomport = self.iomport,  # type: ignore
            appserver = self.appserver,  # type: ignore
            authkey = self.authkey,  # type: ignore
            timeout = self.timeout) # type: ignore
        print ('conexão instanciada')
        return self
FábioRB
  • 335
  • 1
  • 12
  • You could always send a request to the server, and if there is an error you would know they disconnected. – Jordan Aug 08 '23 at 21:57
  • But what would be the magic method to be called that allows me to check for it? – FábioRB Aug 08 '23 at 22:21
  • Why not just call sassession.symexist() to test if a macro variable that is known to always exist, such as SYSVER. If it runs the result should be true. If the session is no alive it should fail, or perhaps time out, or perhaps saspy is smart enough to just start a new session. Try it and see. – Tom Aug 09 '23 at 01:28
  • I will try the symexist(). Didn´t know about it. I´ve asked on saspy github for a easy method to check for alive connection but there isn't. – FábioRB Aug 09 '23 at 02:15

0 Answers0