Advertisement
rfmonk

threading_names_log.py

Feb 3rd, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # this is from The Python
  4. # Standard Library by example
  5. # ISBN13: 9780321767349
  6.  
  7. import logging
  8. import threading
  9. import time
  10.  
  11. logging.basicConfig(
  12.     level=logging.DEBUG,
  13.     format='[%(levelname)s] (%(threadName)-10s) %(message)s',
  14. )
  15.  
  16.  
  17. def worker():
  18.     logging.debug('Starting')
  19.     time.sleep(2)
  20.     logging.debug('Exiting')
  21.  
  22.  
  23. def my_service():
  24.     logging.debug('Starting')
  25.     time.sleep(3)
  26.     logging.debug('Exiting')
  27.  
  28. t = threading.Thread(name='my_service', target=my_service)
  29. w = threading.Thread(name='worker', target=worker)
  30. w2 = threading.Thread(target=worker)  # use default name
  31.  
  32. w.start()
  33. w2.start()
  34. t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement