Friday, 11 December 2015

Python: Specifying target for thread

Following is the definition of Thread constructor.
threading.Thread(group=None, target=None, name=None, args=(), kwargs={}, *, daemon=None)

‘target’ is the callable object to be invoked by the run() method. By using the argument ‘target’ we can specify the target method to invoke.


MyThread.py
import threading

def printData():
 print("Called by thread")
 
def main():
 myThread = threading.Thread(target=printData)
 myThread.start()

if __name__ == "__main__" :
 main()

$ python3 MyThread.py
Called by thread




Previous                                                 Next                                                 Home

No comments:

Post a Comment