#!/usr/bin/env python
import signal
import time
import sys
import multiprocessing
idx = 0
def worker_function():
global idx
idx = idx + 1
print("idx = {0}\n".format(idx))
time.sleep(1)
def main():
for i in range(3):
worker = multiprocessing.Process(target=worker_function, args=())
worker.start()
worker.join()
if __name__ == "__main__":
main()
output is as follows:
idx = 1
idx = 1
idx = 1
Question> Why the python global variable cannot be updated by each individual process?