Q:

Python program to create and delete threads using sleep method

belongs to collection: Python Threading Programs

0

We need to import two libraries: threading and time,

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python program for multithreading with class... >>
<< Python program to illustrate multithreading...