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


Groups > comp.lang.python > #91953

Retrying to send message

From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.python
Subject Retrying to send message
Organization Decebal Computing
Date 2015-06-03 14:27 +0200
Message-ID <87egltht87.fsf@Equus.decebal.nl> (permalink)

Show all headers | 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