本文整理汇总了Python中threading.Thread.Daemon方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.Daemon方法的具体用法?Python Thread.Daemon怎么用?Python Thread.Daemon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threading.Thread
的用法示例。
在下文中一共展示了Thread.Daemon方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: push
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import Daemon [as 别名]
def push(self,req):
sizenum=len(req)
for urls in req:
self.q_request.put(urls)
threadnownum=0
threaddie=[]
dienum=0
if self.isThread==1:
for item in self.Threads:
if item.isAlive():
threadnownum=threadnownum+1
with self.lock:
print str(threadnownum)+'活着的线程数'
self.Threads = filter(lambda x:x.isAlive() !=False,self.Threads)
else:
for item in self.Threads:
if item.is_alive():
threadnownum=threadnownum+1
with self.lock:
print str(threadnownum)+'活着的进程数'
self.Threads = filter(lambda x:x.is_alive()!=False,self.Threads)
print str(len(self.Threads))+'清理后活着的进程数'
sizenumber=min(self.threads_num-threadnownum,sizenum)
if self.isThread==1:
for i in range(sizenumber):
t=Thread(target=self.getTask)
t.Daemon=True
t.start()
self.Threads.append(t)
else:
for i in range(sizenumber):
t=multiprocessing.Process(target=self.getTaskProcess)
t.Daemon=True
t.start()
self.Threads.append(t)
示例2: start
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import Daemon [as 别名]
def start(self):
sizenumber=min(self.threads_num,self.q_request.qsize())
if self.isThread==1:
for i in range(sizenumber):
t = Thread(target=self.getTask)
print '线程'+str(i+1)+' 正在启动'
t.setDaemon(self.deamon)
t.start()
self.Threads.append(t)
with self.lock:
self.alivenum+=1
elif self.isThread==0:
for i in range(sizenumber):
t = multiprocessing.Process(target=self.getTaskProcess)
print '进程'+str(i+1)+' 正在启动'
t.Daemon=self.deamon
t.start()
self.Threads.append(t)
with self.lock:
self.alivenum+=1
else:
for i in range(sizenumber):
t = gevent.spawn(self.getgeventTask)
print '协程' + str(i + 1) + ' 正在启动'
self.Threads.append(t)
with self.lock:
self.alivenum += 1
示例3: get_aggregated_results
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import Daemon [as 别名]
def get_aggregated_results(self):
for url in self.url_list:
self.queue.put(url)
# start a thread for each url
for url in self.url_list:
t = Thread(target=self.get_provider_results)
t.Daemon = True
t.start()
self.queue.join()
# unpack tuple, throw out leading 'agony' value
flights = [t[1] for t in heapq.merge(*self.flights)]
return {'results': flights}
示例4: start
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import Daemon [as 别名]
def start(self):
sizenumber=min(self.threads_num,self.q_request.qsize())
if self.isThread==1:
for i in range(sizenumber):
t = Thread(target=self.getTask)
print '线程'+str(i+1)+' 正在启动'
t.setDaemon(True)
t.start()
self.Threads.append(t)
else:
for i in range(sizenumber):
t = multiprocessing.Process(target=self.getTaskProcess)
print '进程'+str(i+1)+' 正在启动'
t.Daemon=True
t.start()
self.Threads.append(t)
示例5: push
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import Daemon [as 别名]
def push(self,req):
sizenum=len(req)
for urls in req:
self.q_request.put(urls)
threadnownum=0
threaddie=[]
dienum=0
if self.isThread==1:
tempnumb=0
with self.lock:
tempnumb=self.alivenum
if tempnumb<self.threads_num:
for item in self.Threads:
if item.isAlive():
threadnownum=threadnownum+1
with self.lock:
print str(threadnownum)+'活着的线程数'
self.Threads = filter(lambda x:x.isAlive() !=False,self.Threads)
print str(len(self.Threads))+'清理后活着的进程数'
else:
threadnownum=self.threads_num
elif self.isThread==0:
tempnumb=0
with self.lock:
tempnumb=self.alivenum
if tempnumb<self.threads_num:
for item in self.Threads:
if item.is_alive():
threadnownum=threadnownum+1
with self.lock:
print str(threadnownum)+'活着的进程数'
self.Threads = filter(lambda x:x.is_alive()!=False,self.Threads)
print str(len(self.Threads))+'清理后活着的进程数'
else:
threadnownum=self.threads_num
sizenumber=min(self.threads_num-threadnownum,sizenum)
if self.isThread==1:
for i in range(sizenumber):
t=Thread(target=self.getTask)
t.Daemon=self.deamon
t.start()
self.Threads.append(t)
with self.lock:
self.alivenum+=1
elif self.isThread==0:
for i in range(sizenumber):
t=multiprocessing.Process(target=self.getTaskProcess)
t.Daemon=self.deamon
t.start()
self.Threads.append(t)
with self.lock:
self.alivenum+=1
else:
for i in range(self.threads_num):
print 'alive num', self.alivenum, self.threads_num
if self.alivenum <self.threads_num:
t = gevent.spawn(self.getgeventTask)
print '协程' + str(self.alivenum) + ' 正在启动'
self.Threads.append(t)
with self.lock:
self.alivenum += 1
else:
break
self.q_request.join()
示例6:
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import Daemon [as 别名]
response = subprocess.check_output("tcpping -x 1 "+ self.ip.rstrip() + " " +str(self.port), shell=True).split()[7]
except:
response=""
try:
r=float(response)
st = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
out=open(self.ip.rstrip()+".out",'a')
out.write(st+" "+response+"\n")
out.close()
if r>80:
subprocess.call("traceroute "+self.ip.rstrip()+">> "+self.ip.rstrip()+".trace",shell=True)
except:
pass
time.sleep(1800)
if __name__=="__main__":
f=open("USpairIP")
os.chdir("Jun28-2")
for line in f:
to=Node(line.split("'")[1], line.split()[1].split(")")[0])
t=Thread(target=to.ping,args=())
t.Daemon=True
t.start()
time.sleep(.01)
print "all started"