1. PF Contest - Win "Conquering the Physics GRE" book! Click Here to Enter
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Python code using Process class

  1. Nov 9, 2014 #1
    1. The problem statement, all variables and given/known data

    I have the following code (please see below). I want it to return [2,4,6,8,10] which is the function evaluated at the given list [1,2,3,4,5]. I want to do this using the process command.

    My problem is:
    print A returns
    [None, None, None, None, None]
    But I want it to return

    Many thanks in advance.

    2. Relevant equations

    3. The attempt at a solution

    import multiprocessing as mp
    from multiprocessing import Process

    def func(x):
    y = x*2
    print y
    return y

    def OutFunc(f1,a):
    if __name__ == '__main__':
    OutputList = []
    res = []
    for I in range(5):
    p=mp.Process(target=f1, args = (a,))

    for proc in OutputList:
    result = proc.join()
    return res

    A = OutFunc(func,[1,2,3,4,5])
    print A
  2. jcsd
  3. Nov 9, 2014 #2


    Staff: Mentor

    When you post code, please add a [ code ] tag at the top and a [ /code ] tag at the bottom (no extra spaces though). Doing so preserves your indentation, which is crucial in Python code. I have added these tags to your code.
    I have also changed your loop variable from i to j, because i in brackets is interpreted by the forum software as the start of an italics tag.
  4. Nov 9, 2014 #3
    Thank you. I hope it looks clearer now.

    Any help would be very much appreciated.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Threads - Python code using Date
Python ATM script using OOP Dec 31, 2016
Writing a procedure in python Dec 20, 2016
A problem with python code Dec 19, 2016
Matlab code to Python Nov 27, 2016
What is wrong with my code? Nov 3, 2016