Learning Professional Python by Bhimavarapu Usharani;Hemanth Jude D.; & Jude D. Hemanth
Author:Bhimavarapu, Usharani;Hemanth, Jude D.; & Jude D. Hemanth
Language: eng
Format: epub
Publisher: CRC Press LLC
Published: 2024-10-15T00:00:00+00:00
Output
test run() 0
test run() 1
test run() 2
test run() 3
test run() 4
sample run() 0
sample run() 1
sample run() 2
sample run() 3
sample run() 4
In the preceding program the join() method is used, which blocks the remaining threads until the current thread completes its task.
5.4 Synchronizing the Thread
In Python, a lock is started by invoking the lock() method, which returns the new lock. The release() method of the new lock object is exploited to release the lock when it is no longer needed.
import threading
import os
def test1():
print(âtest 1 assigned to thread: {}â.format(threading.current_thread().name))
print(âID of process running test 1: {}â.format(os.getpid()))
def test2():
print(âtest 2 assigned to thread: {}â.format(threading.current_thread().name))
print(âID of process running test 2: {}â.format(os.getpid()))
if __name__ == â__main__â:
# print ID of current process
print(âID of process running main program: {}â.format(os.getpid()))
# print name of main thread
print(âMain thread name: {}â.format(threading.current_thread().name))
# creating threads
t1 = threading.Thread(target=test1, name=ât1â)
t2 = threading.Thread(target=test2, name=ât2â)
# starting threads
t1.start()
t2.start()
# wait until all threads finish
t1.join()
t2.join()
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(22239)
Hello! Python by Anthony Briggs(21443)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(19977)
Dependency Injection in .NET by Mark Seemann(19412)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(19129)
Kotlin in Action by Dmitry Jemerov(19023)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(18602)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(17436)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(16958)
Grails in Action by Glen Smith Peter Ledbrook(16575)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(14130)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(12115)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(10846)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10592)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(9963)
Hit Refresh by Satya Nadella(9109)
The Kubernetes Operator Framework Book by Michael Dame(8535)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8359)
Robo-Advisor with Python by Aki Ranin(8305)