Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94111
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Is this a good way to work with init and exception |
| Date | 2015-07-19 12:35 +0200 |
| Organization | Decebal Computing |
| Message-ID | <87380kzb8b.fsf@Equus.decebal.nl> (permalink) |
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 | Next — Next in thread | Find similar | Unroll 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