Python program to create and delete threads using sleep method

Here, we will create a Python program to create and delete threads using sleep method.
Submitted by Shivang Yadav, on March 16, 2021

We need to import two libraries: threading and time,

  • threading for creating and deleting threads.
  • time for implementing time-based functions.

Program to create and delete threads using sleep method

import threading
import time

class ServiceProvider(threading.Thread):
    def run(self):
      while True:
        print("Service Provider....")
        time.sleep(1)

print("IN MAIN PROGRAM")
S=ServiceProvider()
S.setDaemon(True)
S.start()
time.sleep(5)
print("END OF MAIN PROGRAM")

Output:

IN MAIN PROGRAM
Service Provider....
Service Provider....
Service Provider....
Service Provider....
Service Provider....
Service Provider....
END OF MAIN PROGRAM

Python Threading Programs »





Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.