Sunday, June 16, 2019

Py count thread

import threading
import time


class mythread(threading.Thread):
    def __init__(self, i):
        threading.Thread.__init__(self)
        self.h = i
        # Script will call the function
    def run(self):
        time.sleep(1)
        print("Value send ", self.h)


f = open('C:\Senthil\SenStudy\Python\Date.txt').readlines()
num = threading.activeCount()
x=2for i in f:
    print("Active threads are ", num)
    time.sleep(1)
    if x <= 3:
        thread1 = mythread(i)
        thread1.start()
        x += 1
    else:
        print("Number of Threads are More than 5 .. going to sleep state for 1 mint ..." , threading.activeCount())
        time.sleep(1)

No comments:

Post a Comment