Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # this is from The Python
- # Standard Library by example
- # ISBN13: 9780321767349
- import threading
- import logging
- logging.basicConfig(level=logging.DEBUG,
- format='(%(threadName)-10s) %(message)s',
- )
- def worker_with(lock):
- with lock:
- logging.debug('Lock acquired via with')
- def worker_no_with(lock):
- lock.acquire()
- try:
- logging.debug('Lock acquired directly')
- finally:
- lock.release()
- lock = threading.Lock()
- w = threading.Thread(target=worker_with, args=(lock,))
- nw = threading.Thread(target=worker_no_with, args=(lock,))
- w.start()
- nw.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement