Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!news.albasani.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.python Subject: Ignore error with non-zero exit status (was: How to ignore error with anon-zero exit status) Date: Sun, 20 Dec 2015 22:22:05 +0100 Organization: PointedEars Software (PES) Lines: 71 Message-ID: <3883651.fOIMIIEhYO@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1450646527 24044 eJwFwYERACEIA7CVRGwL42j/2H+ET5AMWofgwWDiFMYueac4cefpLu1qpQV81bB7+CKxFD8U7hCJ (20 Dec 2015 21:22:07 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sun, 20 Dec 2015 21:22:07 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwCAIA7CXtEKFcxyU/09Y4oebdY1O8/GBEmDg6PZX4mSHifUiW88Qyg1M7rsi0U/1ZTxfleog7AdcGxW5 Cancel-Lock: sha1:vqov9RTo+6Q6Szl8yuZqK9pLv4o= X-NNTP-Posting-Host: eJwNyMkBwCAMA7CVgMYGxnGu/UcoegofJ2MbQUOjqSQSd5c0G2xfUQ6WV765LwUpR8VpP/YDQnUS2g== Xref: csiph.com comp.lang.python:100634 Ganesh Pal wrote: > def run_scanner(): > """ > Mount /filesystems and run scanner > """ > for cmd in [" mount /filesystems ", " scanner_start"]: > try: > out, err, ret = run(cmd, timeout=3600) > if ret != 0: > logging.error("Can't run %s got %s (%d)!" % (cmd, err, > ret)) Python 2.6 (why are you using the oldest Python minor version?) introduced string.format(), so you should use that instead of the old string format operator (“%”): logging.error("Can't run {0}; got {1} ({2:d})!".format(cmd, err, ret)) On the other hand, you do not need the format operator to begin with: logging.error("Can't run %s; got %s (%d)!", cmd, err, ret) > return False > except Exception as e: > logging.exception("Failed to run %s got %s" % (cmd, e)) See above. > return False > logging.info("Mount /tmp.....Done !!!") > time.sleep(30) > > > Iam on python 2.6 and Linux , I need you inputs on how to ignore an > specific error when the mount fails (Polite people would *ask* a *question*.) > In general the mount has zero status if it succeeds and anon-zero exit > status if it fails. (“_a non-zero_”, with a space in-between. “anon” can be misunderstood as an abbreviation for “anonymous”.) > 1.But for one rare case the mount succeeds but returns anon-zero exit > status and when we get “Reading GUID from da0xxx: No such file or > directory” error , how to ignore this error and proceed with the above > code If the non-zero exit status is distinguishable from other non-zero statuses, then you just test for that particular status code. Otherwise, you should simply test if the filesystem has been mounted before you proceed. > 2. Also need to add this check only for mount case i.e mount > /filesystems and not scanner_start Most simple solution for this: Do not use a loop. More "complicated" solution: Use an “if” statement. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.