Question: This is a long assignment so I can't post everything but I just need a help on this small part. Here is my instruction... In

This is a long assignment so I can't post everything but I just need a help on this small part.

Here is my instruction...

In the final part of the lab you are going to utilize a ThreadPoolExecutor to load all of the people records in the database. You are going to implement most of this section on your own, but here are a few requirements that should assist your thinking process:

First, create a helper method (outside the PersonDB class) that will act as an intermediary to PersonDBs load_person method:

 def load_person(id, db_file): with PersonDB(db_file) as db: return db.load_person(id) 

You can use this to simplify the future target for the threads.

  • You are to use exactly 10 worker threads (the argument to ThreadPoolExecutor)

  • You must create the ThreadPoolExecutor with a context manager with block

  • The future target is the load_person() function defined above

  • You can assume that the record ids to load are 0 through max_people 1

o Yes, that means you will spawn max_people futures...

  • Try to launch all of the future workers using a comprehension that returns a list of future

    objects so you can use wait() or as_completed() to sync back up on the main thread

  • Put all the resulting records in a list and print it out (will be a big list)

And here is my code.

def load_person(id, db_file):

with PersonDB(db_file) as db:

return db.load_person(id)

def load_all_people():

worker_thread = 10

max_people = -1

with ThreadPoolExecutor(worker_thread) as executor:

futures = [executor.submit(load_person, x) for x in range(max_people)]

for future in as_completed(futures):

print(future.result())

if __name__ == "__main__":

load_all_people()

When I do this, I do not get anything back on my terminal.

Can anyone help me?

Thank you so much in advance.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!