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 165 views
165 views asked Jan 29, 2024 by avibootz
1 answer 246 views
246 views asked May 18, 2018 by avibootz
1 answer 215 views
215 views asked May 18, 2018 by avibootz
1 answer 192 views
192 views asked Feb 6, 2018 by avibootz
1 answer 266 views
...