コード例 #1
0
ファイル: osaBatch.py プロジェクト: hacder/src
def NewIpSubThreed(rev,func,type='batch'):
	'''
	@每IP每线程,执行任务,最大同时执行maxthreed个任务
	'''
	thread_arr = []
	
	if not rev or not func:	
		save_log('ERROR','rev or func Error!')
		return False		
	iplist = batchIpList(rev)
	try:
		q = putBatchIp(iplist)
	except Exception as e:
		save_log('ERROR','BATCH QUEUE is error:'+str(e))
		return False
		
	#while True:
	
	
		
	#线程控制,防止同时执行任务过大导致服务器负载突发
	#for x in xrange(BATCH['maxthreed']):
		
	for x in xrange(q.qsize()):
					
		ip = getBatchIp(q)
		
		try:
			tt = threading.Thread(target=func.index,args=[rev,type,ip,x])
			thread_arr.append(tt)			
		except Exception as e:
			save_log('ERROR','BATCH Threed is error:'+str(e))
			
	for i in xrange(len(thread_arr)):
		try:
			thread_arr[i].setDaemon(0)
			thread_arr[i].start()
		except Exception as e:
			save_log('ERROR','BATCH Threed start is error:'+str(e))
		
	for i in xrange(len(thread_arr)):
		thread_arr[i].join()	
	
	if q.qsize() == 0:
		#此次批量操作执行完成,更新状态
		id = str(getBatchId(rev))
		if type == 'batch':
			usql = "UPDATE `osa_tasknow` SET oStatus = '执行完成' WHERE id = "+id+""			
			try:
				uid = update(usql)
			except Exception as uerror:
				save_log('ERROR','update error,sql is:'+usql+',error info:'+str(uerror))
				
		save_log('INFO','BATCH Threed is ok!')
		return True
	
	return False
コード例 #2
0
def NewIpSubThreed(rev, func, type='batch'):
    '''
	@每IP每线程,执行任务,最大同时执行maxthreed个任务
	'''
    thread_arr = []

    if not rev or not func:
        save_log('ERROR', 'rev or func Error!')
        return False
    iplist = batchIpList(rev)
    try:
        q = putBatchIp(iplist)
    except Exception as e:
        save_log('ERROR', 'BATCH QUEUE is error:' + str(e))
        return False

    #while True:

    #线程控制,防止同时执行任务过大导致服务器负载突发
    #for x in xrange(BATCH['maxthreed']):

    for x in xrange(q.qsize()):

        ip = getBatchIp(q)

        try:
            tt = threading.Thread(target=func.index, args=[rev, type, ip, x])
            thread_arr.append(tt)
        except Exception as e:
            save_log('ERROR', 'BATCH Threed is error:' + str(e))

    for i in xrange(len(thread_arr)):
        try:
            thread_arr[i].setDaemon(0)
            thread_arr[i].start()
        except Exception as e:
            save_log('ERROR', 'BATCH Threed start is error:' + str(e))

    for i in xrange(len(thread_arr)):
        thread_arr[i].join()

    if q.qsize() == 0:
        #此次批量操作执行完成,更新状态
        id = str(getBatchId(rev))
        if type == 'batch':
            usql = "UPDATE `osa_tasknow` SET oStatus = '执行完成' WHERE id = " + id + ""
            try:
                uid = update(usql)
            except Exception as uerror:
                save_log(
                    'ERROR', 'update error,sql is:' + usql + ',error info:' +
                    str(uerror))

        save_log('INFO', 'BATCH Threed is ok!')
        return True

    return False
コード例 #3
0
def ipSubThreed(rev, func, type='batch'):
    '''
	@每IP每线程,执行任务,最大同时执行maxthreed个任务
	'''
    if not rev or not func:
        return False
    iplist = batchIpList(rev)
    try:
        q = putBatchIp(iplist)
    except Exception as e:
        save_log('ERROR', 'BATCH QUEUE is error:' + str(e))
    while True:
        if q.qsize() == 0:
            #此次批量操作执行完成,更新状态
            id = str(getBatchId(rev))
            if type == 'batch':
                usql = "UPDATE `osa_tasknow` SET oStatus = '执行完成' WHERE id = " + id + ""
                try:
                    uid = update(usql)
                except Exception as uerror:
                    save_log(
                        'ERROR', 'update error,sql is:' + usql +
                        ',error info:' + str(uerror))
            break

        #线程控制,防止同时执行任务过大导致服务器负载突发
        for x in xrange(BATCH['maxthreed']):

            ip = getBatchIp(q)
            if ip == None or not ip:
                break
            try:
                tt = threading.Thread(target=func.index,
                                      args=[rev, type, ip, x])
                tt.setDaemon(0)
                tt.start()
            except Exception as e:
                save_log('ERROR', 'BATCH Threed is error:' + str(e))
    time.sleep(300)
コード例 #4
0
ファイル: osaBatch.py プロジェクト: hacder/src
def ipSubThreed(rev,func,type='batch'):
	'''
	@每IP每线程,执行任务,最大同时执行maxthreed个任务
	'''
	if not rev or not func:		
		return False		
	iplist = batchIpList(rev)
	try:
		q = putBatchIp(iplist)
	except Exception as e:
		save_log('ERROR','BATCH QUEUE is error:'+str(e))
	while True:
		if q.qsize() == 0:
			#此次批量操作执行完成,更新状态
			id = str(getBatchId(rev))
			if type == 'batch':
				usql = "UPDATE `osa_tasknow` SET oStatus = '执行完成' WHERE id = "+id+""			
				try:
					uid = update(usql)
				except Exception as uerror:
					save_log('ERROR','update error,sql is:'+usql+',error info:'+str(uerror))
			break
			
		
		#线程控制,防止同时执行任务过大导致服务器负载突发
		for x in xrange(BATCH['maxthreed']):
		
			ip = getBatchIp(q)
			if ip == None or not ip:
				break	
			try:
				tt = threading.Thread(target=func.index,args=[rev,type,ip,x])
				tt.setDaemon(0)
				tt.start()				
			except Exception as e:
				save_log('ERROR','BATCH Threed is error:'+str(e))
	time.sleep(300)