Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91962
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'tries': 0.05; 'except:': 0.07; 'exception,': 0.09; 'logic': 0.09; 'retry': 0.09; 'timeout': 0.09; 'cc:addr:python-list': 0.10; 'exception': 0.13; 'ignore': 0.14; 'def': 0.14; 'wed,': 0.15; 'better?': 0.16; 'bug,': 0.16; 'clause.': 0.16; 'error_msg': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:send': 0.16; 'true:': 0.16; 'useless': 0.16; '{0}': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'else,': 0.18; 'skip': 0.18; ';-)': 0.18; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'assuming': 0.22; 'parameter': 0.22; 'terminate': 0.22; 'try:': 0.22; 'bit': 0.23; '2015': 0.23; 'skip:l 40': 0.23; 'header:In- Reply-To:1': 0.24; 'sort': 0.25; 'not,': 0.27; 'have,': 0.27; 'message-id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'went': 0.28; 'actual': 0.29; 'catching': 0.29; 'sleep': 0.29; 'maybe': 0.31; "i'd": 0.31; 'seconds': 0.31; 'code': 0.31; 'gets': 0.32; 'up.': 0.32; 'implement': 0.32; 'another': 0.34; 'message.': 0.34; 'received:google.com': 0.34; 'skip:c 30': 0.35; 'wrong': 0.35; 'execution': 0.35; 'false': 0.35; 'too': 0.36; 'except': 0.36; 'should': 0.37; 'subject:: ': 0.37; 'pm,': 0.39; 'does': 0.39; 'skip:t 20': 0.40; 'your': 0.60; 'here.': 0.61; 'skip:u 10': 0.62; 'cecil': 0.84; 'chrisa': 0.84; 'westerhof': 0.84; 'to:none': 0.90; 'crucial': 0.91; 'cutting': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=lZ7m7hKJvn/Rb/oAiWVAat0uwr+DoF/T3JY167D/AB0=; b=dY9r9bWSZGytoi9IbNvr9OtowdKj0MBq0ldjGayPkwESzfPNuLWQhTaw96FM1QjmNH uvGwT9Un1LgH9eQ9yoNcM184BAPlFvE5eSDllxTW35QxgXoP0VdG3PeGyeDKUhV/8GBk 8+dqk7AuDxC78ax3btFjKQNcMSv/dKL8w88lBY74d+p9rNPEOIHez4b0RyrQl84ojjWj lFOlzjX1CcZv9ukfpIQytkBwq5mNu4Tgb09/PsXh2kYYSfapXhPZ0D3Pk4uYnuN7ovgu VJeCiNP3QhHBniN8h4MZLydOiLqV/GotqHmq91lq8HNLItaeuRbESznpqDbkp4RhVjNI j7JA== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.143.104 with SMTP id sd8mr14487257igb.14.1433338142255; Wed, 03 Jun 2015 06:29:02 -0700 (PDT) |
| In-Reply-To | <87egltht87.fsf@Equus.decebal.nl> |
| References | <87egltht87.fsf@Equus.decebal.nl> |
| Date | Wed, 3 Jun 2015 23:29:02 +1000 |
| Subject | Re: Retrying to send message |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.108.1433338144.13271.python-list@python.org> (permalink) |
| Lines | 52 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1433338145 news.xs4all.nl 2842 [2001:888:2000:d::a6]:44543 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:91962 |
Show key headers only | View raw
On Wed, Jun 3, 2015 at 10:27 PM, Cecil Westerhof <Cecil@decebal.nl> wrote:
> def send_message(account_id, message, max_tries, terminate_program):
> error_msg = 'Something went wrong with: ' + message
> not_send = True
> tries = 0
> while not_send:
> try:
> Core().update_status(account_id, message)
> except libturpial.exceptions.ServiceOverCapacity:
> tries += 1
> print('Tried to send it {0} times'.format(tries))
> if tries >= max_tries:
> terminate_program(error_msg)
> time.sleep(60)
> except:
> terminate_program(error_msg)
> else:
> not_send = False
>
> Is this a reasonable way to implement this, or is another way better?
> Well, maybe the timeout should be a parameter also. ;-)
I'd skip the not_send flag and do the logic thusly:
while True:
try:
update_status as above
break
except ServiceOverCapacity:
as above
And I'd also skip the bare except clause. If you get any sort of
exception, whether it's a bug, a failure from libturpial, a network
error, or anything else, your code will just terminate with a bland
and useless message. Much better to simply let the exception bubble
up.
> Also the documentation of time.sleep says:
> The actual suspension time may be less than that requested because
> any caught signal will terminate the sleep() following execution
> of that signal’s catching routine.
>
> My program does not much else as sending the message. So I think it is
> not necessary to cover for this possibility. Are I assuming to much?
I wouldn't worry too much about a signal cutting your sleep short; it
doesn't look to me as if "exactly sixty seconds" is all that crucial
here. If your program sleeps for 42.645 seconds and then gets woken up
by a signal, and you retry a bit sooner than you otherwise would have,
is it going to break anything? If not, just ignore that possibility.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Retrying to send message Cecil Westerhof <Cecil@decebal.nl> - 2015-06-03 14:27 +0200
Re: Retrying to send message Chris Angelico <rosuav@gmail.com> - 2015-06-03 23:29 +1000
Re: Retrying to send message Cecil Westerhof <Cecil@decebal.nl> - 2015-06-03 18:15 +0200
Re: Retrying to send message MRAB <python@mrabarnett.plus.com> - 2015-06-03 19:12 +0100
Re: Retrying to send message Ethan Furman <ethan@stoneleaf.us> - 2015-06-03 11:28 -0700
Re: Retrying to send message Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-03 21:37 +0100
Re: Retrying to send message Chris Angelico <rosuav@gmail.com> - 2015-06-04 08:00 +1000
Re: Retrying to send message Ethan Furman <ethan@stoneleaf.us> - 2015-06-03 16:15 -0700
Re: Retrying to send message Cecil Westerhof <Cecil@decebal.nl> - 2015-06-04 07:13 +0200
csiph-web