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.
Deep Learning with Python by François Chollet(12595)
Hello! Python by Anthony Briggs(9928)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9804)
The Mikado Method by Ola Ellnestam Daniel Brolund(9791)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(9411)
Dependency Injection in .NET by Mark Seemann(9348)
Hit Refresh by Satya Nadella(8834)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8310)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7792)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7773)
The Kubernetes Operator Framework Book by Michael Dame(7741)
Grails in Action by Glen Smith Peter Ledbrook(7705)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7570)
Exploring Deepfakes by Bryan Lyon and Matt Tora(7537)
Practical Computer Architecture with Python and ARM by Alan Clements(7458)
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(7438)
Robo-Advisor with Python by Aki Ranin(7415)
Building Low Latency Applications with C++ by Sourav Ghosh(7311)
Svelte with Test-Driven Development by Daniel Irvine(7286)
