Advertisement
rfmonk

threading_time.py

Feb 4th, 2014
115
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 delayed():
  17.     logging.debug('worker running')
  18.     return
  19.  
  20. t1 = threading.Timer(3, delayed)
  21. t1.setName('t1')
  22. t2 = threading.Timer(3, delayed)
  23. t2.setName('t2')
  24.  
  25. logging.debug('starting timers')
  26. t1.start()
  27. t2.start()
  28.  
  29. logging.debug('waiting before canceling %s', t2.getName())
  30. time.sleep(2)
  31. logging.debug('canceling %s', t2.getName())
  32. t2.cancel()
  33. logging.debug('done')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement