python multithreading failure, has only one thread of the solution

When I learn python multithreading, according to the online code, exactly the same! ! Multithreading others, I have been single-threaded, it is outrageous.

code show as below

import threading
import time

def job_1():
    print('This is a new threading')
    for i in range(10):
        time.sleep(0.2)
    print('T1 was finished')

def job_2():
    print('This is a new different threading')
    print('T2 was finished')

def main():
    print(threading.current_thread().getName())
    new_threading_1 = threading.Thread (target = job_1 ())   # define a new thread, the thread name, do what works 
    new_threading_2 = threading.Thread (target = job_2 ())
    new_threading_1.start ()   # add a thread to begin preparations 
    new_threading_2.start ()
     Print ( ' Process Finished WAS ' )
 IF  __name__ == ' __main__ ' :
    main()

But the result is in order, step by step out

 

 After looking at a lot of things in the book Jane found a post: https://www.jianshu.com/p/79372add4c45

Then, shining I changed a bit, and found that really yes. In setting the thread statement, the value of the target's not in brackets

Print (threading.current_thread (). getName ())
     # new_threading_1 = threading.Thread (target = job_1 ()) # define a new thread, the thread name, do what works 
    new_threading_1 = threading.Thread (target = job_1)
     # of the threading.Thread = new_threading_2 (target = job_2 ()) 
    new_threading_2 of the threading.Thread = (target = job_2)

After doing such a small modification, run the program, it can be expected to

 

Guess you like

Origin www.cnblogs.com/This-is-Y/p/12316801.html