Python Forum

Full Version: pool map cycle
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Trying to run twice pool map cycle.
from multiprocessing import Pool
b=["0","0","0","0","0","0"]

def f(c):
    b[5]=c
    return b
for i1 in range(1,3):
    if __name__ == '__main__':
        p = Pool(1)
        print(p.map(f, ["f", "n","x"]))
    b[2]="3"
The program displays the following response:
Output:
[['0', '0', '3', '0', '0', 'f'], ['0', '0', '3', '0', '0', 'n'], ['0', '0', '3', '0', '0', 'x']] [['0', '0', '3', '0', '0', 'f'], ['0', '0', '3', '0', '0', 'n'], ['0', '0', '3', '0', '0', 'x']]
And I need it to be:
Output:
[['0', '0', '0', '0', '0', 'f'], ['0', '0', '0', '0', '0', 'n'], ['0', '0', '0', '0', '0', 'x']] [['0', '0', '3', '0', '0', 'f'], ['0', '0', '3', '0', '0', 'n'], ['0', '0', '3', '0', '0', 'x']]
Why does the first line print 3 ?
I just ran your code and got:
Output:
[['0', '0', '0', '0', '0', 'f'], ['0', '0', '0', '0', '0', 'n'], ['0', '0', '0', '0', '0', 'x']] [['0', '0', '3', '0', '0', 'f'], ['0', '0', '3', '0', '0', 'n'], ['0', '0', '3', '0', '0', 'x']]
So, I cann't reproduce the problem.
Thank you. One last question. What version of Python did you use? I can not achieve this result.
Python 3.7.1 [GCC 7.3.0]
Installed the same version, but not yet displays:
Output:
[['0', '0', '3', '0', '0', 'f'], ['0', '0', '3', '0', '0', 'n'], ['0', '0', '3', '0', '0', 'x']] [['0', '0', '3', '0', '0', 'f'], ['0', '0', '3', '0', '0', 'n'], ['0', '0', '3', '0', '0', 'x']]

maybe the problem is in the encoding

try to test your code with the addition of a string of ASCII # -*- coding: ASCII -*-
# -*- coding: ASCII -*-
from multiprocessing import Pool
b=["0","0","0","0","0","0"]
 
def f(c):
    b[5]=c
    return b
for i1 in range(1,3):
    if __name__ == '__main__':
        p = Pool(1)
        print(p.map(f, ["t", "n","x"]))
    b[2]="3"
tried to execute the same code on the website https://repl.it/languages/python3 and it worked. This site uses Python interpreter 3.6.1 (default, Dec 2015, 13:05:11)[GCC 4.8.2] on linux

and I tried to run the code on windows so it did not work