Skip to content

Commit

Permalink
Fixed last try/except/finally clauses (#239)
Browse files Browse the repository at this point in the history
As we drop support for Python 2.4 and 2.5, this change uses unified
try/except/finally clauses that were not supported before.

Change-Id: I9f11cf0db71ba183f60432115a3a018727361dd5
  • Loading branch information
thiell committed Aug 9, 2017
1 parent 05033db commit d20eb4a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
54 changes: 26 additions & 28 deletions lib/ClusterShell/Engine/Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,38 +711,36 @@ def run(self, timeout):
if self.running:
raise EngineAlreadyRunningError()

# note: try-except-finally not supported before python 2.5
try:
self.running = True
# start port clients
self.start_ports()
# peek in ports for early pending messages
self.snoop_ports()
# start all other clients
self.start_clients()
# run loop until all clients and timers are removed
self.runloop(timeout)
except EngineTimeoutException:
self.clear(did_timeout=True)
raise
except: # MUST use BaseException as soon as possible (py2.5+)
# The game is over.
exc_t, exc_val, exc_tb = sys.exc_info()
try:
# start port clients
self.start_ports()
# peek in ports for early pending messages
self.snoop_ports()
# start all other clients
self.start_clients()
# run loop until all clients and timers are removed
self.runloop(timeout)
except EngineTimeoutException:
self.clear(did_timeout=True)
raise
except: # MUST use BaseException as soon as possible (py2.5+)
# The game is over.
exc_t, exc_val, exc_tb = sys.exc_info()
try:
# Close Engine clients
self.clear()
except:
# self.clear() may still generate termination events that
# may raises exceptions, overriding the other one above.
# In the future, we should block new user events to avoid
# that. Also, such cases could be better handled with
# BaseException. For now, print a backtrace in debug to
# help detect the problem.
tbexc = traceback.format_exception(exc_t, exc_val, exc_tb)
LOGGER.debug(''.join(tbexc))
raise
# Close Engine clients
self.clear()
except:
# self.clear() may still generate termination events that
# may raises exceptions, overriding the other one above.
# In the future, we should block new user events to avoid
# that. Also, such cases could be better handled with
# BaseException. For now, print a backtrace in debug to
# help detect the problem.
tbexc = traceback.format_exception(exc_t, exc_val, exc_tb)
LOGGER.debug(''.join(tbexc))
raise
raise
finally:
# cleanup
self.timerq.clear()
Expand Down
17 changes: 7 additions & 10 deletions lib/ClusterShell/Worker/Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,14 @@ def _on_remote_node_close(self, node, rc, gateway):
tarfileobj.write(buf)
tarfileobj.flush()
tarfileobj.seek(0)
tmptar = tarfile.open(fileobj=tarfileobj)
try:
tmptar = tarfile.open(fileobj=tarfileobj)
try:
self.logger.debug("%s extracting %d members in dest %s",
node, len(tmptar.getmembers()),
self.dest)
tmptar.extractall(path=self.dest)
except IOError as ex:
self._on_remote_node_msgline(node, ex, 'stderr',
gateway)
# note: try-except-finally not supported before python 2.5
self.logger.debug("%s extracting %d members in dest %s",
node, len(tmptar.getmembers()),
self.dest)
tmptar.extractall(path=self.dest)
except IOError as ex:
self._on_remote_node_msgline(node, ex, 'stderr', gateway)
finally:
tmptar.close()
self._rcopy_bufs = {}
Expand Down

0 comments on commit d20eb4a

Please sign in to comment.