How to use multiple threads

前端 未结 5 1692
臣服心动
臣服心动 2021-02-05 11:16

I have this code:

import thread

def print_out(m1, m2):
    print m1
    print m2
    print \"\\n\"

for num in range(0, 10):
    thread.start_new_thread(print_o         


        
5条回答
  •  [愿得一人]
    2021-02-05 12:11

    You should let the main thread stay alive for a little while. If the main thread dies, so will all the other threads and hence you will not see any output. Try adding a time.sleep(0.1) at the end of the code and then you will see the output.

    After that, you can have a look at the thread.join() to get more idea about this.

提交回复
热议问题