Skip to content

Instantly share code, notes, and snippets.

@whoiscarlo
Created October 7, 2016 22:45
Show Gist options
  • Save whoiscarlo/de7f7250743deac7882f8fc2afc6e0ad to your computer and use it in GitHub Desktop.
Save whoiscarlo/de7f7250743deac7882f8fc2afc6e0ad to your computer and use it in GitHub Desktop.
Threading with Lock
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