In the code below, I was expecting the output to be 2 as I'm changing the value of config before assigning function to pool for multiprocessing, but instead I'm getting 5. I'm sure there is a good reason for it, but not sure how to explain it.
from multiprocessing import Pool
config = 5
class Test:
def __init__(self):
print("This is init")
@classmethod
def testPrint(cls, data):
print(config)
print("This is testPrint")
return config
if __name__ == "__main__" :
pool = Pool()
config = 2
output = pool.map(Test.testPrint, range(10))
print(output)
Output
5
This is testPrint
5
This is testPrint
5
This is testPrint
5
This is testPrint
5
This is testPrint
5
This is testPrint
5
This is testPrint
5
This is testPrint
5
This is testPrint
5
This is testPrint
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5]