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
- # This program didn't work on my system
- # and illuminated a bug in logging.
- import random
- import threading
- import time
- import logging
- logging.basicConfig(level=logging.DEBUG,
- format='(%(threadingName)-10s) %(message)s',
- )
- def worker():
- """thread worker function"""
- t = threading.currentThread() # pyflakes complains here. local
- # variable 't' is assigned but never used.
- pause = random.randint(1, 5)
- logging.debug('sleeping %s', pause)
- time.sleep(pause)
- logging.debug('ending')
- return
- for i in range(3):
- t = threading.Thread(target=worker)
- t.setDaemon(True)
- t.start()
- main_thread = threading.currentThread()
- for t in threading.enumerate():
- if t is main_thread:
- continue
- logging.debug('joining %s', t.getName())
- t.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement