Skip to content

Commit

Permalink
Use exceptionpexpect instead of baseexception
Browse files Browse the repository at this point in the history
  • Loading branch information
remh committed Mar 11, 2013
1 parent 5185bb5 commit d175a4c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions checks/jmx_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ def connected(self):
return self._jmx is not None and self._jmx.isalive()

def terminate(self):
from pexpect import ExceptionPexpect
if self._jmx is not None:
try:
self._jmx.sendline("bye")
except BaseException, e:
except ExceptionPexpect, e:
pass

try:
self._jmx.terminate(force=True)
except BaseException, e:
except ExceptionPexpect, e:
pass

self._jmx = None
Expand Down Expand Up @@ -106,7 +107,7 @@ def connect(self, connection, user=None, passwd=None, timeout=20, priority=DEFAU
self._jmx = pexpect.spawn(cmd, timeout = timeout)
self._jmx.delaybeforesend = 0
self._wait_prompt()
except BaseException, e:
except ExceptionPexpect, e:
self.terminate()
raise Exception('Error when connecting to JMX Service at address %s. JMX Connector will be relaunched.\n%s' % (connection, str(e)))

Expand All @@ -117,6 +118,7 @@ def dump_domains(self, domains, values_only=True):
return d

def dump(self, domain=None, values_only=True):
from pexpect import ExceptionPexpect
"""Returns a dictionnary of all beans and attributes
If values_only parameter is true, only numeric values will be fetched by
Expand Down Expand Up @@ -160,7 +162,7 @@ def dump(self, domain=None, values_only=True):
self._jmx.sendline(cmd)
self._wait_prompt()
content = self._jmx.before.replace(cmd,'').strip()
except BaseException, e:
except ExceptionPexpect, e:
self.log.critical("POPEN error while dumping data. \n JMX Connector will be relaunched \n %s" % str(e))
self.terminate()
raise
Expand Down

0 comments on commit d175a4c

Please sign in to comment.