I'm going to increase start
global variable in the multi-process python,
Source :
from multiprocessing import Process, Lock
start = 0
def printer(item, lock):
"""
Prints out the item that was passed in
"""
global start
lock.acquire()
try:
start = start + 1
print(start)
finally:
lock.release()
if __name__ == '__main__':
lock = Lock()
items = ['tango', 'foxtrot', 10]
for item in items:
p = Process(target=printer, args=(item, lock))
p.start()
Output:
1
1
1
I use lock for start
counter but it doesn't work,
I was expecting to see this output:
1 # ==> start = 1
2 # ==> start = start + 1 = 2
3 # ==> start = start + 1 = 3