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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:44:30+00:00 2026-06-03T04:44:30+00:00

In the example code below, I’d like to get the return value of the

  • 0

In the example code below, I’d like to get the return value of the function worker. How can I go about doing this? Where is this value stored?

Example Code:

import multiprocessing

def worker(procnum):
    '''worker function'''
    print str(procnum) + ' represent!'
    return procnum


if __name__ == '__main__':
    jobs = []
    for i in range(5):
        p = multiprocessing.Process(target=worker, args=(i,))
        jobs.append(p)
        p.start()

    for proc in jobs:
        proc.join()
    print jobs

Output:

0 represent!
1 represent!
2 represent!
3 represent!
4 represent!
[<Process(Process-1, stopped)>, <Process(Process-2, stopped)>, <Process(Process-3, stopped)>, <Process(Process-4, stopped)>, <Process(Process-5, stopped)>]

I can’t seem to find the relevant attribute in the objects stored in jobs.

  • 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-03T04:44:32+00:00Added an answer on June 3, 2026 at 4:44 am

    Use a shared variable to communicate. For example, like this,

    Example Code:

    import multiprocessing
    
    
    def worker(procnum, return_dict):
        """worker function"""
        print(str(procnum) + " represent!")
        return_dict[procnum] = procnum
    
    
    if __name__ == "__main__":
        manager = multiprocessing.Manager()
        return_dict = manager.dict()
        jobs = []
        for i in range(5):
            p = multiprocessing.Process(target=worker, args=(i, return_dict))
            jobs.append(p)
            p.start()
    
        for proc in jobs:
            proc.join()
        print(return_dict.values())
    

    Output:

    0 represent!
    1 represent!
    3 represent!
    2 represent!
    4 represent!
    [0, 1, 3, 2, 4]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to do this... I'll give example code below. But I can't
In the example code below, I get this error : Element TestSerializeDictionary123.Customer.CustomProperties vom Typ
UPDATE 2011.09.13 This bug has been resolved by Adobe. The example code below now
I've simplified my JavaScript code to the example below; this code is giving me
(the example code below is self-contained and runnable, you can try it, it won't
In my example code below i would like to replace the item in the
I can't seem to see the problem with the example code below. For some
The source code below is an example code snippet about my problem. I expect
In my example code below, you can see that I have been trying to
Example code below; function a() { var a = 123; //some stuff b(); }

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.