How to create n number of threads

Discussion in 'Python' started by hisan, Jun 28, 2011.

  1. hisan

    hisan Guest

    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
     
    hisan, Jun 28, 2011
    #1
    1. Advertising

  2. hisan

    Ian Kelly Guest

    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()

    for thread in threads:
    thread.join()
     
    Ian Kelly, Jun 28, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HVPQ
    Replies:
    5
    Views:
    875
  2. yoda
    Replies:
    2
    Views:
    472
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  3. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    439
    William Ahern
    Aug 27, 2004
  4. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,508
    Arne Vajhøj
    Apr 9, 2008
  5. Une bévue
    Replies:
    0
    Views:
    177
    Une bévue
    Jun 14, 2006
Loading...

Share This Page