This article describes the Python multi-process synchronization simple implementation code. Share to everyone for your reference, as follows:
#encoding =utf8from multiprocessing Import Process, lockdef func (Lock, a): lock.acquire () print a Lock.release () if __name__ = = ' __main__ ': lock = lock () workers = [] # Create two processes for I in range (0, 2): p = Process (target = func, args = (lock, i)) P.start () workers.append (P) # waits for all processes to end for p in WORKERS:
p.join ()
More interested in Python related content readers can view this site topic: "Python data structure and algorithm tutorial", "Python Socket Programming Skills Summary", "Python function Tips Summary", "Python string manipulation Skills summary", " Python Introductory and Advanced Classic tutorials and Python file and directory Operations Tips Summary
I hope this article is helpful for Python program design.