import threading
import time
gj=0
lock=threading.Lock()
def g_num(j=0):
global gj
if j==1:
if lock.acquire():
gj+=1
lock.release()
class TestThread(threading.Thread):
def __init__(self, thread_num, ipaddr):
super(TestThread, self).__init__()
self.thread_num = thread_num
self.ipaddr=ipaddr
self.stopped = False
#self.timeout = timeout
def run(self):
n=0
while not self.stopped:
print "%s : %s - %s"%(self.thread_num,n,self.ipaddr)
if n==2:
g_num(1)
n=0
n+=1
time.sleep(1)
def stop(self):
self.stopped = True
def restart(self):
self.stopped = False
def isStopped(self):
return self.stopped
def t_func(thread_num):
n=0
while 1:
print "
python 多线程http失败切换功能
最新推荐文章于 2023-04-16 11:54:05 发布