def setup_class(cls): GenericTestThread.setup_class.im_func(cls) # if we cannot start more than, say, 1000 threads on this OS, then # we can check that we get the proper error at app-level space = cls.space lock = thread.allocate_lock() lock.acquire() def f(): lock.acquire() lock.release() start = thread._count() try: try: for i in range(1000): thread.start_new_thread(f, ()) finally: lock.release() except (thread.error, MemoryError): cls.w_can_start_many_threads = space.wrap(False) else: cls.w_can_start_many_threads = space.wrap(True) # wait a bit to allow all threads to finish now remaining = thread._count() retries = 0 while remaining > start: retries += 1 if retries == 200: raise Exception("the test's threads don't stop!") time.sleep(0.2) remaining = thread._count()
def test_thread_count(self): import thread, time feedback = [] please_start = [] def f(): feedback.append(42) self.waitfor(lambda: please_start) assert thread._count() == 0 thread.start_new_thread(f, ()) self.waitfor(lambda: feedback) assert thread._count() == 1 please_start.append(1) # trigger
def threading_cleanup(nb_threads): _MAX_COUNT = 10 for count in range(_MAX_COUNT): n = thread._count() if n == nb_threads: break time.sleep(0.1)
def vuln_start(): ''' 开启扫描任务 ''' init() PASSWORD_DIC, THREAD_COUNT, TIMEOUT, WHITE_LIST = get_config() thread.start_new_thread(monitor, ()) while True: task_id, task_plan, task_target, task_plugin = queue_get() if task_id == '': time.sleep(10) continue if PLUGIN_DB: del sys.modules[PLUGIN_DB.keys()[0]] # 清理插件缓存 PLUGIN_DB.clear() for task_netloc in task_target: while True: if int(thread._count()) < THREAD_COUNT: if task_netloc[0] in WHITE_LIST: break thread.start_new_thread( vulscan, (task_id, task_netloc, task_plugin)) break else: time.sleep(2) if task_plan == 0: na_task.update({"_id": task_id}, {"$set": {"status": 2}})
def run2(): global state print lock.acquire(0) print "num threads:", _count() state = 1 print lock.acquire() lock.release() state = 2
def set_proxy(ip, port): host = ip port = port backlog = 5 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server.bind((host, port)) server.listen(10) print "you have set proxy successly now you can use the hair warsh app for free\nEnjoy it" while True: thread.start_new_thread(Proxy(server).run, ()) #print "success" print "当前链接数目为%d" % (thread._count())
def make_request(threadName,delay): try: resp = requests.get("http://CloudApp-env.p4qatt7jd3.sa-east-1.elasticbeanstalk.com/insert/%s" % threadName, headers="") count = 0 while resp.status_code == 200: count += 1 if count == 5: thread.start_new_thread(make_request, ("%s0" % threadName, 1,)) count = 0 time.sleep(delay) resp = requests.get("http://CloudApp-env.p4qatt7jd3.sa-east-1.elasticbeanstalk.com/insert/%s" % threadName, headers="") except: print("Got error after created the %s thread!" % thread._count()) os._exit(1)
def getprocess(): time.sleep(5) while True: progressLock.acquire() if targetList.qsize() > 0: processnum = 100 - round( float(targetList.qsize()) / targetListCount, 2) * 100 if processnum != 100: print 'process:' + str(processnum) + '%' else: if thread._count() > 1: print 'scanthreadnum:' + str( thread._count()) + ' wait for DogScan' else: print 'process done' break else: if thread._count() <= 1: print 'process done' exit() print 'scanthreadnum:' + str(thread._count()) progressLock.release() time.sleep(10)
def monitor(): global PASSWORD_DIC, THREAD_COUNT, TIMEOUT, WHITE_LIST while True: queue_count = na_task.find({"status": 0, "plan": 0}).count() if queue_count: load = 1 else: ac_count = thread._count() load = float(ac_count - 4) / THREAD_COUNT if load > 1: load = 1 if load < 0: load = 0 na_heart.update({"name": "load"}, {"$set": {"value": load, "up_time": datetime.datetime.now()}}) PASSWORD_DIC, THREAD_COUNT, TIMEOUT, WHITE_LIST = get_config() if load > 0: time.sleep(8) else: time.sleep(60)
def answer(l=[]): els = [] for e in l: found = True # print len(els) for i in range(len(els)): # print i,e if els[i][0] <= e: found = False els[i] = [e] + els[i] if found: els.append([e]) count = 0 for e in els: # print(e) e.reverse() thread.start_new_thread(mod, (e, )) while thread._count() > 0: pass global gcount return gcount
'data': str({i: '1'}) }) targetList.put({ 'url': sys.argv[2], 'method': 'GET', 'data': '', 'cookie': { i: '1' } }) targetListCount = targetList.qsize() while True: try: scan_data = [] if not targetList.empty(): target = targetList.get() elif int(thread._count()) < 1: print "Fuzz Param Done" break else: continue while True: if int(thread._count()) < threadCount: thread.start_new_thread( fuzz, (target, lenUrl, timeOut, targetList)) break else: time.sleep(2) except Exception as e: print e
plugin_info['add_time'] = time_ plugin_info['filename'] = plugin_name plugin_info['count'] = 0 del plugin_info['plugin'] na_plugin.insert(plugin_info) except: pass if __name__ == '__main__': init() PASSWORD_DIC, THREAD_COUNT, TIMEOUT, WHITE_LIST = get_config() thread.start_new_thread(monitor, ()) while True: task_id, task_plan, task_target, task_plugin = queue_get() if task_id == '': time.sleep(10) continue if PLUGIN_DB: del sys.modules[PLUGIN_DB.keys()[0]] # 清理插件缓存 PLUGIN_DB.clear() for task_netloc in task_target: while True: if int(thread._count()) < THREAD_COUNT: if task_netloc[0] in WHITE_LIST: break thread.start_new_thread(vulscan, (task_id, task_netloc, task_plugin)) break else: time.sleep(2) if task_plan == 0: na_task.update({"_id": task_id}, {"$set": {"status": 2}})
def threading_setup(): if thread: return thread._count(), else: return 1,
import thread, os, time #thread.start_new_thread def syscall(cmd, crap=None): os.system(cmd) #run transition models thread.start_new_thread(syscall,('python run_LFKT-trans-diff-gauss_L1.py x_axis',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff-gauss_L1.py y_axis',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff-gauss_L1.py center',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff-gauss_L1.py shape',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff-gauss_L1.py spread',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff-gauss_L1.py h_to_d',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff-gauss_L1.py d_to_h',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff-gauss_L1.py histogram',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff_L1.py x_axis',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff_L1.py y_axis',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff_L1.py center',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff_L1.py shape',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff_L1.py spread',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff_L1.py h_to_d',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff_L1.py d_to_h',0) ) thread.start_new_thread(syscall,('python run_LFKT-trans-diff_L1.py histogram',0) ) time.sleep(10) print "ASDFASDGASDFGASDFG" print thread._count()
def threading_setup(): return thread._count(),
#!/usr/bin/python import os,commands,time,socket,thread def ins(ip): #print "chup rh betichod" installed=commands.getstatusoutput("sshpass -p darwin ssh {} 'rpm -q sshpass'".format(ip)) if installed[0]!=0: s=commands.getstatusoutput("sshpass -p darwin scp hadoop1/Initiation/sp.rpm root@{}:/tmp/ ".format(ip)) #print(s) s=commands.getstatusoutput("sshpass -p darwin ssh {} 'rpm -ivh /tmp/sp.rpm' ".format(ip)) #print s #listscan=['192.168.43.198','192.168.43.104'] for each in listscan: #print each s=commands.getstatusoutput("ping -c 1 {}".format(each)) #print(s[0]) thread.start_new_thread(ins,(each,)) #print thread._count() while thread._count()!=0: time.sleep(3) print "installer ended"
def threading_setup(): if thread: return (thread._count(),) else: return (1,)
import thread import time # Define a function for the thread def print_time( threadName, delay): count = 0 while count < 5: time.sleep(delay) count += 1 print "%s(%s): %s" % ( threadName, thread._count(), time.ctime(time.time()) ) # Create two threads as follows try: thread.start_new_thread( print_time, ("Thread-1", 1, ) ) thread.start_new_thread( print_time, ("Thread-2", 2, ) ) except: print "Error: unable to start thread" while 1: time.sleep(1) if thread._count() <= 0 : thread.exit()
values.reverse() file_name = "done.dat" if os.path.exists(file_name): done_index = joblib.load(file_name) else: done_index = 0 for index, row in enumerate(values): if index < done_index:continue ip_s, ip_e, ip_num, ip_issue = row logger.info("scan ip_range: %s --> %s" %(ip_s, ip_e)) scan_range(ip_s, ip_e) joblib.dump(index, file_name, compress=3) # ip_s = "180.97.0.0" # ip_e = "180.97.33.255" # scan_range(ip_s, ip_e) time.sleep(5) b_stoped = 0 while NUM_Lock: if NUM_Lock <= 5: b_stoped += 1 thread_count = thread._count() if thread_count == 0: break logger.info("thread count: %d" % (thread_count)) if b_stoped > 120: break time.sleep(1) time_e = time.time() logger.info("cost: %ds" %(time_e-time_s))
def print_time( threadName, delay): count = 0 while count < 5: time.sleep(delay) count += 1 print "%s(%s): %s" % ( threadName, thread._count(), time.ctime(time.time()) )
plugin_info['add_time'] = time_ plugin_info['filename'] = plugin_name plugin_info['count'] = 0 del plugin_info['plugin'] na_plugin.insert(plugin_info) except: pass if __name__ == '__main__': init() PASSWORD_DIC, THREAD_COUNT, TIMEOUT = get_config() thread.start_new_thread(monitor, ()) while True: task_id, task_plan, task_target, task_plugin = queue_get() if task_id == '': time.sleep(10) continue PLUGIN_DB = {} # 清理插件缓存 for task_netloc in task_target: # print task_netloc while True: if int(thread._count()) < THREAD_COUNT: thread.start_new_thread( vulscan, (task_id, task_netloc, task_plugin)) break else: time.sleep(2) if task_plan == 0: na_task.update({"_id": task_id}, {"$set": {"status": 2}})
print type(allocate_lock()) print_lock = allocate_lock() done = 0 def run(arg): global done with print_lock: print "num threads:", _count() print "in other thread!", arg done = 1 print "starting!" print "num threads:", _count() with print_lock: t = start_new_thread(run, (5,)) print type(t) while not done: time.sleep(0) print "done!" print "num threads:", _count() done = False with print_lock: t = start_new_thread(run, (), {'arg': 6}) while not done: time.sleep(0)
def run(arg): global done with print_lock: print "num threads:", _count() print "in other thread!", arg done = 1
maxThreads = 10 def printThreadName(threadName): count = 0 while count < 10: time.sleep(1) count += 1 print("%d: %s\n" % (thread.get_ident(), time.ctime(time.time()))) thread.exit() #Create Threads threads = [] try: count = 0 while count < maxThreads: tid = thread.start_new_thread(printThreadName, (count, )) print("TID: %s\n" % tid) threads.append(tid) count += 1 except: print "Error: unable to start thread" while 1: time.sleep(2) print(threads) print("Number of Threads %s" % thread._count()) pass