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


Groups > comp.lang.python > #91953

Retrying to send message

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!storethat.news.telefonica.de!telefonica.de!news.panservice.it!feed.xsnews.nl!border02.ams.xsnews.nl!feeder04.ams.xsnews.nl!feeder03.ams.xsnews.nl!abp001.ams.xsnews.nl!frontend-F10-18.ams.news.kpn.nl
From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.python
Subject Retrying to send message
Organization Decebal Computing
X-Face "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E
X-Homepage http://www.decebal.nl/
Date Wed, 03 Jun 2015 14:27:52 +0200
Message-ID <87egltht87.fsf@Equus.decebal.nl> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Cancel-Lock sha1:kKd6k4Y6CYGm7Kd/SKuvGvsTc5I=
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Lines 39
NNTP-Posting-Host 81.207.62.244
X-Trace 1433334595 news.kpn.nl 21189 81.207.62.244@kpn/81.207.62.244:33474
Xref csiph.com comp.lang.python:91953

Show key headers only | View raw


I am using libturpial to post messages on Twitter. Sometimes I get a
libturpial.exceptions.ServiceOverCapacity.

It is a good idea to try it again then. For this I wrote the following
function:
    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. ;-)


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?

-- 
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

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