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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:38:52+00:00 2026-05-17T22:38:52+00:00

I asked a related but very general question earlier (see especially this response ).

  • 0

I asked a related but very general question earlier (see especially this response).

This question is very specific. This is all the code I care about:

result = {}
for line in open('input.txt'):
  key, value = parse(line)
  result[key] = value

The function parse is completely self-contained (i.e., doesn’t use any shared resources).

I have Intel i7-920 CPU (4 cores, 8 threads; I think the threads are more relevant, but I’m not sure).

What can I do to make my program use all the parallel capabilities of this CPU?

I assume I can open this file for reading in 8 different threads without much performance penalty since disk access time is small relative to the total time.

  • 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-17T22:38:53+00:00Added an answer on May 17, 2026 at 10:38 pm

    cPython does not provide the threading model you are looking for easily. You can get something similar using the multiprocessing module and a process pool

    such a solution could look something like this:

    def worker(lines):
        """Make a dict out of the parsed, supplied lines"""
        result = {}
        for line in lines.split('\n'):
            k, v = parse(line)
            result[k] = v
        return result
    
    if __name__ == '__main__':
        # configurable options.  different values may work better.
        numthreads = 8
        numlines = 100
    
        lines = open('input.txt').readlines()
    
        # create the process pool
        pool = multiprocessing.Pool(processes=numthreads)
    
        # map the list of lines into a list of result dicts
        result_list = pool.map(worker, 
            (lines[line:line+numlines] for line in xrange(0,len(lines),numlines) ) )
    
        # reduce the result dicts into a single dict
        result = {}
        map(result.update, result_list)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see this question asked a lot in the related questions, but my need
This is related to this question I asked earlier about syntax highlighting user-defined blocks
This is very similar to a question I asked the other day but my
This is very similar to a question I asked the other day but my
This is closely related to anothewr question I have asked but since this is
I asked a related question about findbugs, but let's ask a more general question.
I already asked this question before, but without any good response, my problem is
In a related question I asked how to get input via IUP . This
Related to an earlier question I asked, I've seen that there's both LoadComponent() and
Related to a question I asked earlier here , I've found a problem which

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.