Advertisement
rfmonk

threading_subclass_args.py

Feb 4th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 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 logging
  9.  
  10. logging.basicConfig(level=logging.DEBUG,
  11.                     format='(%(threadName)-10s) %(message)s',
  12.                     )
  13.  
  14.  
  15. class MyThreadWithArgs(threading.Thread):
  16.  
  17.     def __init__(self, group=None, target=None, name=None,
  18.                  args=(), kwargs=None, verbose=None):
  19.         threading.Thread.__init__(self, group=group,
  20.                                   target=target,
  21.                                   name=name,
  22.                                   verbose=verbose)
  23.         self.args = args
  24.         self.kwargs = kwargs
  25.         return
  26.  
  27.     def run(self):
  28.         logging.debug('running with %s and %s',
  29.                       self.args, self.kwargs)
  30.         return
  31.  
  32. for i in range(5):
  33.     t = MyThreadWithArgs(args=(i,),
  34.                          kwargs={'a': 'A', 'b': 'B'})
  35.     t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement