0
import time
import threading
class test:

    def printer():
        for  i in range(3):
            print('Hello')
            time.sleep(5)
    def reload():
        for i in range(3):
            print('hey')
    def upload():
        print('hii')



if __name__ == '__main__':
    thread1 = threading.Thread(target=printer())
    thread2 = threading.Thread(target=reload())
    thread3 = threading.Thread(target=upload())
    thread1.start()
    thread3.start()
    thread2.start()
    thread1.join()
    thread2.join()
    thread3.join()
    print("bye")
    print("right")
def doc():
    for  i in range(3):
        print('good')

output:

hello
hello
hello
hey
hey
hey
hii
bye
right

I want to print def doc after thread1, thread2 and thread3 terminted...."bye" and "right" are printed by main thread but doc() didn't print. Why does it not print?

jps
  • 15,760
  • 14
  • 59
  • 71

1 Answers1

0

def doc(): is merely defining the doc method. If you want its result printed, you need to call it. I would suggest you move that block before your if statement, then add a doc() call as the last line in your if statement. So the last few lines of the If block would appear as follows:

print(“bye”)
print(“right”)
doc()
Steven W. Klassen
  • 1,216
  • 9
  • 24