Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6021925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:47:03+00:00 2026-05-23T03:47:03+00:00

retVal = None retries = 5 success = False while retries > 0 and

  • 0
retVal = None
retries = 5
success = False
while retries > 0 and success == False:
    try:
        retVal = graph.put_event(**args)
        success = True
    except:
        retries = retries-1
        logging.info('Facebook put_event timed out.  Retrying.')
return success, retVal

In the code above, how can I wrap this whole thing up as a function and make it so that any command (in this example, ‘graph.put_event(**args)’) can be passed in as a parameter to be executed within the function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:47:04+00:00Added an answer on May 23, 2026 at 3:47 am

    To directly answer your question:

    def foo(func, *args, **kwargs):
        retVal = None
        retries = 5
        success = False
        while retries > 0 and success == False:
            try:
                retVal = func(*args, **kwargs)
                success = True
            except:
                retries = retries-1
                logging.info('Facebook put_event timed out.  Retrying.')
        return success, retVal
    

    This can then be called as such:

    s, r = foo(graph.put_event, arg1, arg2, kwarg1="hello", kwarg2="world")
    

    As an aside, given the above task, I would write it along the lines of:

    class CustomException(Exception): pass
    
    # Note: untested code...
    def foo(func, *args, **kwargs):
        retries = 5
        while retries > 0:
            try:
                return func(*args, **kwargs)
            except:
                retries -= 1
                # maybe sleep a short while
        raise CustomException
    
    # to be used as such
    try:
        rv = foo(graph.put_event, arg1, arg2, kwarg1="hello", kwarg2="world")
    except CustomException:
        # handle failure
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code : private boolean callHttpPost() { boolean retVal = false; HttpClient httpclient =
I have the following extremely basic $.ajax function: function doAjax(url, args){ var retVal =
I have the following code: public List<IWFResourceInstance> FindStepsByType(IWFResource res) { List<IWFResourceInstance> retval = new
let retVal = if reader.Read() then (reader.GetString(0), getBytesData reader 1, reader.GetDateTime(2)) else null F#
Hi I Opening a popup like this: function openPopup() { RetVal = window.showModalDialog(chooseProducts.aspx, ,
in javascript i can call prompt like this var retVal = prompt(Enter the new
The following LINQ: retval = ( from jm in entities.JobMasters where jm.UserId == userId
I set 4 datatables as members of my class like this: With retval .LookupData
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel *retval = (id)view; if
Suddenly I got EXC_BAD_ACCESS on this line: int retVal = UIApplicationMain(argc, argv, nil, nil);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.