thread example question

Mark Hammond skippy.hammond at gmail.com
Wed Jan 18 00:27:13 EST 2012


On 18/01/2012 4:22 PM, Rodrick Brown wrote:
> import _thread as thread
> import time
>
> class thread_counter(object):
>      def __init__(self, thr_cnt, sleep_int):
>          self.thr_cnt = thr_cnt
>          self.sleep_int = sleep_int
>
> def counter(myId, count):
>      for i in range(count):
>          time.sleep(1)
>          print('[{}] => {}'.format(myId, i))
>
> def main():
>      for i in range(5):
>          thread.start_new_thread(counter, (i, 5))

I think you meant for the following 2 lines to be outside the loop (ie, 
to be dedented one level).  Once you do that the output is as *I* expect :)

Mark

>          time.sleep(6)
>          print('Main thread exiting..')
>
> if __name__ == '__main__':
>      main()
>




More information about the Python-list mailing list