How to create n number of threads

How to create n number thread in python. i want iterate over the for loop and create a thread for each iteration .
sample code
for i in range(o,50):
i want to create 50 thread here which call the same function. how start and stop each thread after completion

Advertisements

On Tue, Jun 28, 2011 at 1:33 PM, hisan <> wrote:
> How to create n number thread in python. i want iterate over the for loopand create a thread for each iteration .
> sample code
> for i in range(o,50):
> i want to create 50 thread here which call the same function. how start and stop each thread after completion

from threading import Thread

threads = [Thread(target=func) for i in range(50)]
for thread in threads:
thread.start()

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!