How to create a thread program that start N threads and each thread output their id in Python

1 Answer

0 votes
import threading


class T(threading.Thread):
    def __init__(self, number):
        self.__id = number
        threading.Thread.__init__(self)

    def run(self):
        print(str(self.__id))

for i in range(5):
    T(i).start()

'''
run:
  
0
1
2
3
4

'''

 



answered Jun 25, 2018 by avibootz

Related questions

1 answer 175 views
175 views asked Jan 29, 2024 by avibootz
1 answer 250 views
250 views asked May 18, 2018 by avibootz
1 answer 219 views
219 views asked May 18, 2018 by avibootz
1 answer 202 views
202 views asked Feb 6, 2018 by avibootz
1 answer 277 views
...