[code.view]

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

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """Naming threads
     """
     #end_pymotw_header
     
     import threading
     import time
     
     def worker():
         print threading.currentThread().getName(), 'Starting'
         time.sleep(2)
         print threading.currentThread().getName(), 'Exiting'
     
     def my_service():
         print threading.currentThread().getName(), 'Starting'
         time.sleep(3)
         print threading.currentThread().getName(), 'Exiting'
     
     t = threading.Thread(name='my_service', target=my_service)
     w = threading.Thread(name='worker', target=worker)
     w2 = threading.Thread(target=worker) # use default name
     
     w.start()
     w2.start()
     t.start()
     

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

contact | logmethods.com