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