Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'restart': 0.09; 'python': 0.11; 'mostly': 0.14; 'changes': 0.15; '(data': 0.16; 'concurrent': 0.16; 'effect,': 0.16; 'occurs.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'undo': 0.16; 'exception': 0.16; 'library': 0.18; 'otherwise,': 0.22; 'header:User-Agent:1': 0.23; 'primary': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'external': 0.29; 'usually': 0.31; 'relational': 0.31; 'writes:': 0.31; 'but': 0.35; 'there': 0.35; 'consistent': 0.36; 'done': 0.36; 'charset:us-ascii': 0.36; 'e.g.': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'ensure': 0.60; 'even': 0.60; 'transaction.': 0.60; 'back': 0.62; 'received:217': 0.63; 'kind': 0.63; 'such': 0.63; 'side': 0.67; 'limitations,': 0.84; 'persistent': 0.84; 'rolls': 0.84; 'transactions': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: dieter Subject: Re: Exception Handling Date: Fri, 10 Apr 2015 08:11:51 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e08d05.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:pnh0w7UOpiQMoUqdu5Lg+AyeF8A= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1428646323 news.xs4all.nl 2870 [2001:888:2000:d::a6]:47700 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:88770 Palpandi writes: > Is there any way to roll back or undo changes which are all done before exception occurs. You are mostly interested in such a function when you handle persistent data (data which persists across program activations - otherwise, you can always quit the current program and restart it again). Python usually does not handle persistent data by itself but uses some kind of library or external system - e.g. a relational database. Those external components may support the concept of "transaction". Their primary function is to ensure a consistent persistant state in view of concurrent modifications. As a side effect, they support a "rollback" which rolls back all modifications to persistent data made by the rolled back transaction. With some limitations, you can use the Python modules "ZODB3" and "transaction" (available on "PyPI") to use transactions in your program - even if you are not interested in persistent data. Its "rollback" will not undo all changes but only changes to "ZODB object"s.