Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pool map cycle
#1
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 ?
Reply
#2
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.
Reply
#3
Thank you. One last question. What version of Python did you use? I can not achieve this result.
Reply
#4
Python 3.7.1 [GCC 7.3.0]
Reply
#5
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"
Reply
#6
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing a cycle to find the nearest point from the array Tysrusko 0 196 May-10-2024, 11:49 AM
Last Post: Tysrusko
  Multiprocessing Pool Multiple Instances How to Kill by Pool ID sunny9495 0 802 Nov-16-2022, 05:57 AM
Last Post: sunny9495
  Need to fix SyntaxError in cycle try alexfrol86 14 3,303 Mar-27-2022, 07:53 AM
Last Post: stevendaprano
  Pool multiprocessing - know current status in loop? korenron 0 1,670 Jul-28-2021, 08:49 AM
Last Post: korenron
  pool mysql error - not catch by try\except? korenron 1 2,193 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  Trying to cycle through a list of charcters pooky2483 12 4,644 Sep-28-2020, 06:55 AM
Last Post: pooky2483
  <while> cycle is not interrupted when using the <random>module ShityCoder 3 2,255 Sep-04-2020, 04:05 PM
Last Post: ShityCoder
  Cycle of numpy variables Zero01 0 1,586 Jul-31-2020, 11:58 AM
Last Post: Zero01
  stop cycle while windows11 1 2,080 May-16-2020, 03:17 PM
Last Post: deanhystad
  Process (pool,map) strange behaviour maverick76 1 1,978 Feb-03-2020, 02:43 PM
Last Post: maverick76

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020