Created
October 7, 2016 22:45
-
-
Save whoiscarlo/de7f7250743deac7882f8fc2afc6e0ad to your computer and use it in GitHub Desktop.
Threading with Lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
def work(arg, qlock): | |
''' | |
Create user file | |
''' | |
qlock.acquire() | |
print arg | |
qlock.release() | |
def startThread(self): | |
qlock = threading.Lock() | |
workerList = [] | |
for each in ['a','b','c', 'd']: | |
threadWorker = threading.Thread(target=work, args=(key, qlock)) | |
threadWorker.start() | |
workerList.append(threadWorker) | |
for each in workerList: | |
each.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment