[code.view]

[top] / python / PyMOTW / threading / threading_daemon.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """Daemon vs. non-daemon threads.
     """
     #end_pymotw_header
     
     import threading
     import time
     import logging
     
     logging.basicConfig(level=logging.DEBUG,
                         format='(%(threadName)-10s) %(message)s',
                         )
     
     def daemon():
         logging.debug('Starting')
         time.sleep(2)
         logging.debug('Exiting')
     
     d = threading.Thread(name='daemon', target=daemon)
     d.setDaemon(True)
     
     def non_daemon():
         logging.debug('Starting')
         logging.debug('Exiting')
     
     t = threading.Thread(name='non-daemon', target=non_daemon)
     
     d.start()
     t.start()
     

[top] / python / PyMOTW / threading / threading_daemon.py

contact | logmethods.com