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


Groups > comp.lang.python > #94111

Is this a good way to work with init and exception

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.python
Subject Is this a good way to work with init and exception
Date Sun, 19 Jul 2015 12:35:16 +0200
Organization Decebal Computing
Lines 42
Message-ID <87380kzb8b.fsf@Equus.decebal.nl> (permalink)
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="528adfd6ad074c92fdc6a7f8fb9e23d8"; logging-data="23218"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2+9NbTg3y74svQ7KtsrdAYb2RVJdmjSo="
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
X-Homepage http://www.decebal.nl/
Cancel-Lock sha1:MtIFgqVXoCFMiH7Cdtf2Sc5IjXc= sha1:3AG0KAGtDqLbCgbu1H+QvSnaxSg=
Xref csiph.com comp.lang.python:94111

Show key headers only | View raw


I am using libturpial to post things on Twitter. But sometimes I get a
ServiceOverCapacity exception. So I wrote the following code.

======================================================================
class InitAlreadyDoneError(Exception):
    pass


##### Functions
def init(max_tries = 5, wait_time = 60):
    global _core

    if _core != None:
        raise InitAlreadyDoneError
    tries = 0
    while True:
        try:
            _core = Core()
            break
        except ServiceOverCapacity:
            tries += 1
            sys.stderr.write('Tried to init _core it {0} times\n'.format(tries))
            sys.stderr.flush()
            if tries >= max_tries:
                raise
            time.sleep(wait_time)
======================================================================

Is this the correct way to work user defined exceptions, or should I
also define a default message?

I use this in the following way:
    import twitterDecebal
    twitterDecebal.init()

Because you can not give parameters with an import as far as I can
see. Is this a good way to do this, or is there a better way?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


Thread

Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-19 12:35 +0200
  Re: Is this a good way to work with init and exception Chris Angelico <rosuav@gmail.com> - 2015-07-19 22:59 +1000
    Re: Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-19 18:46 +0200
      Re: Is this a good way to work with init and exception Chris Angelico <rosuav@gmail.com> - 2015-07-20 04:11 +1000
        Re: Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-19 21:10 +0200
          Re: Is this a good way to work with init and exception Chris Angelico <rosuav@gmail.com> - 2015-07-20 07:08 +1000
            Re: Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-20 00:19 +0200
              Re: Is this a good way to work with init and exception Chris Angelico <rosuav@gmail.com> - 2015-07-20 08:40 +1000
                Re: Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-20 01:27 +0200

csiph-web