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 269 views
269 views asked Jan 29, 2024 by avibootz
1 answer 327 views
327 views asked May 18, 2018 by avibootz
1 answer 304 views
304 views asked May 18, 2018 by avibootz
1 answer 291 views
291 views asked Feb 6, 2018 by avibootz
1 answer 379 views
...