[code.view]

[top] / python / PyMOTW / sys / sys_checkinterval_io.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2009 Doug Hellmann All rights reserved.
     #
     """
     """
     #end_pymotw_header
     
     import sys
     import threading
     from Queue import Queue
     import time
     
     def show_thread(q, extraByteCodes):
         for i in range(5):
             for j in range(extraByteCodes):
                 pass
             #q.put(threading.current_thread().name)
             print threading.current_thread().name
         return
     
     def run_threads(prefix, interval, extraByteCodes):
         print '%(prefix)s interval = %(interval)s with %(extraByteCodes)s extra operations' % locals()
         sys.setcheckinterval(interval)
         q = Queue()
         threads = [ threading.Thread(target=show_thread, name='%s T%s' % (prefix, i), 
                                      args=(q, extraByteCodes)
                                      )
                     for i in range(3)
                   ]
         for t in threads:
             t.start()
         for t in threads:
             t.join()
         while not q.empty():
             print q.get()
         print
         return
     
     run_threads('Default', interval=100, extraByteCodes=1000)
     run_threads('Custom', interval=10, extraByteCodes=0)
     

[top] / python / PyMOTW / sys / sys_checkinterval_io.py

contact | logmethods.com