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 8426325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:30:50+00:00 2026-06-10T04:30:50+00:00

I have a database with 10,000 adam_id ‘s. For each adam_id , I need

  • 0

I have a database with 10,000 adam_id‘s. For each adam_id, I need to pull down information through an API.

My table looks like this:

`title`
- adam_id
- success (boolean)
- number_of_tries (# of times success=0 when trying to do the pull down)

Here is the function I would like to create:

def pull_down(cursor):
    work_remains = True
    while work_remains:
        cursor.execute("""SELECT adam_id FROM title WHERE success=0 
                          AND number_of_tries < 5 ORDR BY adam_id LIMIT 1""")
        if len(cursor.fetchall()):
            adam_id = cursor.fetchone()[0]
            do_api_call(adam_id)
        else:
            work_remains = False

def do_api_call(adam_id):
    # do api call
    if success:
        cursor.execute("UPDATE title SET success=1 WHERE adam_id = adam_id")
    else:
        cursor.execute("UPDATE title SET number_of_tries+=1 WHERE adam_id=adam_id")

How would I do the above with n workers using python’s multiprocessing functionality instead of doing it with one synchronous process? I have begun looking over the Multiprocessing module ( http://docs.python.org/library/multiprocessing.html ), but it seems pretty hard to digest for me thus far.

  • 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-06-10T04:30:51+00:00Added an answer on June 10, 2026 at 4:30 am

    If the heavy part of the work is the api call, because it goes to an outside resource, then that would be the only part you really would want to make parallel. The database calls are probably really fast. So you might try this:

    1. Batch get the adam_id values in one query
    2. Put the ids into a process pool to do the API calls
    3. Get the results and commit them to the database

    This is a rough pseudocode example to show the logic flow:

    from multiprocessing import Pool
    
    def pull_down(cursor):
        # get all the data in one query
        count = cursor.execute("""SELECT adam_id FROM title WHERE success=0 
                          AND number_of_tries < 5 ORDR BY adam_id LIMIT 1""")
        if count:
            # Step #1
            adam_id_list = [row[0] for row in cursor.fetchall()]
    
            # Step #2
            pool = Pool(4)
            results = pool.map(do_api_call, adam_id_list)
            pool.close()
    
            # Step #3
            update_db(results)
    
    def do_api_call(adam_id):
        # do api call
        success = call_api_with_id(adam_id)
        return (adam_id, success)
    
    def update_db(results):
        # loop over results and built batch queries for the success
        # or failed items
    
        # (obviously this split up could be optimized)
        succeeded = [result[0] for result in results if result[1]]
        failed = [result[0] for result in results if not result[1]]
    
        submit_success(succeeded)
        submit_failed(failed)
    

    It would only complicate the code if you tried to make the database calls parallel, because then you have to properly give each process it’s own connection, when really it wouldn’t be the database slowing you down anyways.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database with ~100,000 entries - right now my query looks like
I have a database with over 30,000 tables and ~40-100 rows in each table.
I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
I have a database with almost 100,000 comments and I would like to detect
I have a MYSQL database with 50.000 rows. Each row represents an article. I
I have a SQL Server database with 500,000 records in table main . There
I have a table (session) in a database which has almost 72,000 rows. I
Suppose I have a database containing 500,000 records, each representing, say, an animal. What
I have a database of approximately 8,000 records. Each record has 1 text field
I have a database table with 10,000,000+ rows which I process to create a

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.