1

So i'm learning python and in one of the courses they were talking about threading this is basically the same code he was using and it was running concurrently in the course but when I run it it runs consecutively and I don't know why?

import threading
import time

threads = []

def printtest():
    print("myname is test")
    time.sleep(3)
    print("done")


for i in range(5):
    th = threading.Thread(target=printtest())
    th.start()
    threads.append(th)


for th in threads:
    th.join()
nivekdrol
  • 41
  • 5
  • 4
    This is a common error. You called `printtest()` and tried to use its result as the function to be used in the thread. You should `th = threading.Thread(target=printtest)`. This is a dup. – tdelaney May 28 '20 at 00:39
  • dam thanks lol your awesome – nivekdrol May 28 '20 at 00:46

0 Answers0