خرید بک لینک

Vote count: 0

I have a code in which I am implementing multi-threading in Python 2.7. However there is one global value which refuses to change. Even after explicitly changing it, when I call the function, the initial value is retained. Can anyone tell me a way around or why is this happening?

Here is a an example. The value of y in the function f does not seem to change even after changing it.

from multiprocessing import Pool
global y
y=10

def f(x):
    retu x*y

def doMultithreading():
    p = Pool(5)
    print(p.map(f, [1,2,3,4,5]))
    y=20
    print y
    print(p.map(f, [1,2,3,4,5]))

if __name__ == '__main__':
    doMultithreading()

The output is

[10, 20, 30, 40, 50]
20
[10, 20, 30, 40, 50]

Ideally isn't it reasonable to expect

[10, 20, 30, 40, 50]
20
[20, 40, 60, 80, 100]

asked 6 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 27 خرداد 1395 ساعت: 20:03

صفحه بندی