Im guessing this is what you want:
from threading import Lock, Thread
x = 0
lock = Lock()
def main():
global x
print(x)
p = Thread(target=change, args=(1,))
p2 = Thread(target=change, args=(2,))
p.start()
p2.start()
p.join()
p2.join()
def change(number):
global x
with lock:
x = x + 1
print('{} - coming from process #{}'.format(x, number))
if __name__ == '__main__':
main()
output:
0
1 - coming from process #1
2 - coming from process #2
this you will notice will not work:
from multiprocessing import Process
from threading import Lock
x = 0
lock = Lock()
def main():
global x
print(x)
p = Process(target=change, args=(1,))
p2 = Process(target=change, args=(2,))
p.start()
p2.start()
p.join()
p2.join()
def change(number):
global x
with lock:
x = x + 1
print('{} - coming from process #{}'.format(x, number))
if __name__ == '__main__':
main()
output:
0
1 - coming from process #1
1 - coming from process #2
thats because Process is like your exwife - she doesnt care about you, and will keep 100% of the stuff when she last saw it. So its 0 first, and it will copy 0 and will never look at x again. Unlike Thread she likes to share.