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 182 views
182 views asked Jan 29, 2024 by avibootz
1 answer 253 views
253 views asked May 18, 2018 by avibootz
1 answer 224 views
224 views asked May 18, 2018 by avibootz
1 answer 210 views
210 views asked Feb 6, 2018 by avibootz
1 answer 281 views
...