Advertisement
rfmonk

threading_daemon_join_timeout.py

Feb 3rd, 2014
111
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 threading
  8. import time
  9. import logging
  10.  
  11. logging.basicConfig(level=logging.DEBUG,
  12.                     format='(%(threadName)-10s) %(message)s',
  13.                     )
  14.  
  15.  
  16. def daemon():
  17.     logging.debug('Starting')
  18.     time.sleep(2)
  19.     logging.debug('Exiting')
  20.  
  21. d = threading.Thread(name='daemon', target=daemon)
  22. d.setDaemon(True)
  23.  
  24.  
  25. def non_daemon():
  26.     logging.debug('Starting')
  27.     logging.debug('Exiting')
  28.  
  29. t = threading.Thread(name='non-daemon', target=non_daemon)
  30.  
  31. d.start()
  32. t.start()
  33.  
  34. d.join(1)
  35. print 'd.isAlive()', d.isAlive()
  36. t.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement