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 191 views
191 views asked Jan 29, 2024 by avibootz
1 answer 255 views
255 views asked May 18, 2018 by avibootz
1 answer 228 views
228 views asked May 18, 2018 by avibootz
1 answer 221 views
221 views asked Feb 6, 2018 by avibootz
1 answer 286 views
...