August 2015
Intermediate to advanced
286 pages
5h 42m
English
Using arguments to identify or name the thread is cumbersome and unnecessary. Each Thread instance has a name with a default value that can be changed as the thread is created. Naming threads is useful in server processes with multiple service threads that handle different operations.
To determine which thread is running, we create three target functions and import the time module to introduce a suspend execution of two seconds:
import threading import time def first_function(): print (threading.currentThread().getName()+\ str(' is Starting \n')) time.sleep(2) print (threading.currentThread().getName()+\ str( ' is Exiting \n')) return def second_function(): print (threading.currentThread().getName()+\ ...Read now
Unlock full access