Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94525

Re: register cleanup handler

From Rob Gaddi <rgaddi@technologyhighland.invalid>
Newsgroups comp.lang.python
Subject Re: register cleanup handler
Date 2015-07-24 20:44 +0000
Organization A noiseless patient Spider
Message-ID <mou83b$i05$3@dont-email.me> (permalink)
References <motjor$vv$1@ger.gmane.org> <201507241547.t6OFlh5t027843@fido.openend.se> <mailman.953.1437753734.3674.python-list@python.org>

Show all headers | View raw


On Fri, 24 Jul 2015 12:01:58 -0400, Neal Becker wrote:

> 
> This would work, but is not very elegant.  I hope for a better way.
> 
> need_cleanup = False try:
>    if (condition):
>       do_something_needing_cleanup need_cleanup = True
>    else:
>       do_something_else
>    code_executed_unconditionally
> finally:
>    if need_cleanup:
>      do_cleanup

if condition:
  try:
    do_something_needing_cleanup()
    code_executed_unconditionally()
  finally:
    do_cleanup()

else:
  do_something_else()
  code_executed_unconditionally()



-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: register cleanup handler Neal Becker <ndbecker2@gmail.com> - 2015-07-24 12:01 -0400
  Re: register cleanup handler Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-07-24 20:44 +0000

csiph-web