Python threading.activeCount() Examples
The following are 30
code examples of threading.activeCount().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
threading
, or try the search function
.
Example #1
Source File: plugins.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 7 votes |
def start(self): if self.finalized: self.bus.log('Already deamonized.') # forking has issues with threads: # http://www.opengroup.org/onlinepubs/000095399/functions/fork.html # "The general problem with making fork() work in a multi-threaded # world is what to do with all of the threads..." # So we check for active threads: if threading.activeCount() != 1: self.bus.log('There are %r active threads. ' 'Daemonizing now may cause strange failures.' % threading.enumerate(), level=30) self.daemonize(self.stdin, self.stdout, self.stderr, self.bus.log) self.finalized = True
Example #2
Source File: nullinux.py From nullinux with MIT License | 6 votes |
def rid_cycling(self, target, ridrange, max_threads): print("\n\033[1;34m[*]\033[1;m Performing RID Cycling for: {}".format(target)) if not self.domain_sid: print_failure("RID Failed: Could not attain Domain SID") return False # Handle custom RID range input try: r = ridrange.split("-") rid_range = list(range(int(r[0]), int(r[1])+1)) except: print_failure("Error parsing custom RID range, reverting to default") rid_range = list(range(500, 551)) for rid in rid_range: try: Thread(target=self.rid_thread, args=(rid,target,), daemon=True).start() except: pass while activeCount() > max_threads: sleep(0.001) while activeCount() > 1: sleep(0.001)
Example #3
Source File: AlarmManager_test.py From LightUpPi-Alarm with MIT License | 6 votes |
def test_set_alarm_thread_edit(self): """ Tests the __set_alarm_thread when an existing alarm thread is inputted. No need to check for input with wrong ID as that gets dealt with in the AlarmThread class and unit test. """ first_alarm = AlarmItem(self.hour, 34, label='test', alarm_id=96, days=(True, True, True, True, True, True, True), enabled=True) new_alarm = AlarmItem(self.hour, 34, enabled=False, alarm_id=96, label='test replace', days=(False, False, False, False, False, False, False)) alarm_mgr = AlarmManager() alarm_mgr.delete_all_alarms() numb_threads = threading.activeCount() launch_success = alarm_mgr._AlarmManager__set_alarm_thread(first_alarm) self.assertTrue(launch_success) self.assertGreater(threading.activeCount(), numb_threads) # Editing to the new alarm data should stop the thread as it is inactive launch_success = alarm_mgr._AlarmManager__set_alarm_thread(new_alarm) self.assertFalse(launch_success) self.assertEqual(threading.activeCount(), numb_threads)
Example #4
Source File: AlarmManager_test.py From LightUpPi-Alarm with MIT License | 6 votes |
def test_stop_alarm_thread(self): """ Test that the __stop_alarm_thread private method will stop a running Alarm Thread, which due to the nature of the thread code can take up to 10 seconds. This test accesses private methods. """ alarm = AlarmItem(self.hour, 34, enabled=True, label='t', alarm_id=96, days=(False, True, True, True, True, True, True)) alarm_mgr = AlarmManager() alarm_mgr.delete_all_alarms() numb_threads = threading.activeCount() launch_success = alarm_mgr._AlarmManager__set_alarm_thread(alarm) self.assertTrue(launch_success) self.assertGreater(threading.activeCount(), numb_threads) stop_success = alarm_mgr._AlarmManager__stop_alarm_thread(alarm.id_) self.assertTrue(stop_success) self.assertEqual(threading.activeCount(), numb_threads)
Example #5
Source File: AlarmManager_test.py From LightUpPi-Alarm with MIT License | 6 votes |
def test_stop_all_alarm_threads(self): """ Launches 2 alarms threads, checks they are running and them stops them all and checks again. """ alarm_one = AlarmItem( self.hour, 34, enabled=True, alarm_id=31, days=(False, False, False, False, False, False, True)) alarm_two = AlarmItem( self.hour, 34, enabled=True, alarm_id=32, days=(False, False, False, False, False, False, True)) alarm_mgr = AlarmManager() # There is a bit of circular dependency here as delete all will execute # __stop_all_alarm_threads alarm_mgr.delete_all_alarms() launch_success = alarm_mgr._AlarmManager__set_alarm_thread(alarm_one) self.assertTrue(launch_success) launch_success = alarm_mgr._AlarmManager__set_alarm_thread(alarm_two) self.assertTrue(launch_success) numb_threads = threading.activeCount() self.assertGreaterEqual(numb_threads, 2) delete_success = alarm_mgr._AlarmManager__stop_all_alarm_threads() self.assertTrue(delete_success) self.assertEqual(threading.activeCount(), numb_threads - 2)
Example #6
Source File: pysoxy.py From pysoxy with GNU General Public License v2.0 | 6 votes |
def main(): """ Main function """ new_socket = create_socket() bind_port(new_socket) signal(SIGINT, exit_handler) signal(SIGTERM, exit_handler) while not EXIT.get_status(): if activeCount() > MAX_THREADS: sleep(3) continue try: wrapper, _ = new_socket.accept() wrapper.setblocking(1) except socket.timeout: continue except socket.error: error() continue except TypeError: error() sys.exit(0) recv_thread = Thread(target=connection, args=(wrapper, )) recv_thread.start() new_socket.close()
Example #7
Source File: F-Scrack.py From F-Scrack with GNU General Public License v3.0 | 6 votes |
def t_join(m_count): tmp_count = 0 i = 0 if I < m_count: count = len(ip_list) + 1 else: count = m_count while True: time.sleep(4) ac_count = threading.activeCount() #print ac_count,count if ac_count < count and ac_count == tmp_count: i+=1 else: i=0 tmp_count = ac_count #print ac_count,queue.qsize() if (queue.empty() and threading.activeCount() <= 1) or i > 5: break
Example #8
Source File: pyssltest.py From MARA_Framework with GNU Lesser General Public License v3.0 | 6 votes |
def status(): ready = 0 inva = 0 errc = 0 pend = 0 print '\n' * 100 for key in jobtrack: if jobtrack[key] =="Not Tested": pend = pend + 1 elif jobtrack[key] =="Invalid": inva = inva + 1 elif jobtrack[key] =="ERROR": errc = errc + 1 elif jobtrack[key] =="READY": ready = ready + 1 print "\n There are " + str(pend) + " pending" print "\n There are " + str(inva) + " Invalid" print "\n There are " + str(errc) + " errors" print "\n There are " + str(ready) + " ready" print "\n There are " + str(threading.activeCount()) + " Threads"
Example #9
Source File: F-Scrack.py From F-Scrack with GNU General Public License v3.0 | 6 votes |
def t_join(m_count): tmp_count = 0 i = 0 if I < m_count: count = len(ip_list) + 1 else: count = m_count while True: time.sleep(4) ac_count = threading.activeCount() #print ac_count,count if ac_count < count and ac_count == tmp_count: i+=1 else: i=0 tmp_count = ac_count #print ac_count,queue.qsize() if (queue.empty() and threading.activeCount() <= 1) or i > 5: break
Example #10
Source File: smarthome.py From smarthome with GNU General Public License v3.0 | 6 votes |
def list_threads(self, txt): cp_threads = 0 http_threads = 0 for thread in threading.enumerate(): if thread.name.find("CP Server") == 0: cp_threads += 1 if thread.name.find("HTTPServer") == 0: http_threads +=1 self._logger.info("list_threads: {} - Number of Threads: {} (CP Server={}, HTTPServer={}".format(txt, threading.activeCount(), cp_threads, http_threads)) for thread in threading.enumerate(): if thread.name.find("CP Server") != 0 and thread.name.find("HTTPServer") != 0: self._logger.info("list_threads: {} - Thread {}".format(txt, thread.name)) return ################################################################# # Item Methods #################################################################
Example #11
Source File: __init__.py From enumdb with GNU General Public License v3.0 | 6 votes |
def launcher(args): try: if args.shell: print_status("Initiating SQL shell..") shell_launcher(args) else: print_status("Starting enumeration...") print_status("Users : {}".format(len(args.users))) print_status("Targets: {}".format(len(args.target))) print_status("Time : {}\n".format(datetime.now().strftime('%m-%d-%Y %H:%M:%S'))) for t in args.target: x = Thread(target=enum_db().db_main, args=(args, t,)) x.daemon = True x.start() # Do not exceed max threads while activeCount() > args.max_threads: sleep(0.001) # Exit all threads before closing while activeCount() > 1: sleep(0.001) except KeyboardInterrupt: print("\n[!] Key Event Detected...\n\n") exit(0)
Example #12
Source File: HeartLeak.py From HeartLeak with MIT License | 6 votes |
def scan(nhost, port, nthread): hFile=open("heartleaked.log", "a") global n print("[+] Running a scan to find %d vulnerable host(s). Be patient!"%nhost) n=nhost while n>0: try: ip=randomHost() try: while threading.activeCount()>nthread: time.sleep(5) t=threading.Thread(target=leakTest, args=(hFile, ip, port)) t.start() except: time.sleep(5) except KeyboardInterrupt: print("[-] Cancelled due to keyboard interruption") break hFile.close() return
Example #13
Source File: plugins.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def start(self): if self.finalized: self.bus.log('Already deamonized.') # forking has issues with threads: # http://www.opengroup.org/onlinepubs/000095399/functions/fork.html # "The general problem with making fork() work in a multi-threaded # world is what to do with all of the threads..." # So we check for active threads: if threading.activeCount() != 1: self.bus.log('There are %r active threads. ' 'Daemonizing now may cause strange failures.' % threading.enumerate(), level=30) self.daemonize(self.stdin, self.stdout, self.stderr, self.bus.log) self.finalized = True
Example #14
Source File: tango.py From Tango with Apache License 2.0 | 6 votes |
def getInfo(self): """ getInfo - return various statistics about the Tango daemon """ stats = {} stats['elapsed_secs'] = time.time() - self.start_time; stats['job_requests'] = Config.job_requests stats['job_retries'] = Config.job_retries stats['waitvm_timeouts'] = Config.waitvm_timeouts stats['runjob_timeouts'] = Config.runjob_timeouts stats['copyin_errors'] = Config.copyin_errors stats['runjob_errors'] = Config.runjob_errors stats['copyout_errors'] = Config.copyout_errors stats['num_threads'] = threading.activeCount() return stats # # Helper functions #
Example #15
Source File: http_dispatcher.py From XX-Net-mini with GNU General Public License v3.0 | 5 votes |
def to_string(self): now = time.time() worker_rate = {} for w in self.workers: worker_rate[w] = w.get_rtt_rate() w_r = sorted(list(worker_rate.items()), key=operator.itemgetter(1)) out_str = 'thread num:%d\r\n' % threading.activeCount() for w, r in w_r: out_str += "%s score:%d rtt:%d running:%d accept:%d live:%d inactive:%d processed:%d" % \ (w.ip_str, w.get_score(), w.rtt, w.keep_running, w.accept_task, (now-w.ssl_sock.create_time), (now-w.last_recv_time), w.processed_tasks) if w.version == "2": out_str += " continue_timeout:%d streams:%d ping_on_way:%d remote_win:%d send_queue:%d\r\n" % \ (w.continue_timeout, len(w.streams), w.ping_on_way, w.remote_window_size, w.send_queue.qsize()) elif w.version == "1.1": out_str += " Trace:%s" % w.get_trace() out_str += "\r\n Speed:" for speed in w.speed_history: out_str += "%d," % speed out_str += "\r\n" out_str += "\r\n working_tasks:\r\n" for unique_id in self.working_tasks: task = self.working_tasks[unique_id] out_str += task.to_string() return out_str
Example #16
Source File: test_threading_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_activeCount(self): activeBefore = threading.activeCount() activeCount = 10 for i in range(activeCount): t = Thread(target=self._sleep, args=(i,)) t.setDaemon(0) t.start() polls = activeCount while activeCount > activeBefore and polls > 0: time.sleep(1) activeCount = threading.activeCount() polls -= 1 self.assertTrue(activeCount <= activeBefore, 'activeCount should to be <= %s, instead of %s' % (activeBefore, activeCount))
Example #17
Source File: pyscan.py From darkc0de-old-stuff with GNU General Public License v3.0 | 5 votes |
def scan(self, host, start, stop): self.port = start while self.port <= stop: while threading.activeCount() < MAX_THREADS: Scanner(host, self.port).start() self.port += 1
Example #18
Source File: AlarmManager_test.py From LightUpPi-Alarm with MIT License | 5 votes |
def test_set_alarm_thread(self): """ Test that the __set_alarm_thread private method will only launch an Alarm Thread if there is an active alarm. Ensure the thread has been launched successfully. This test accesses private methods. """ alarm = AlarmItem(self.hour, 34, days=(True, True, True, True, True, True, True), enabled=False, label='test', alarm_id=96) alarm_mgr = AlarmManager() alarm_mgr.delete_all_alarms() numb_threads = threading.activeCount() # Test setting inactive alarm launch_success = alarm_mgr._AlarmManager__set_alarm_thread(alarm) self.assertFalse(launch_success) self.assertEqual(threading.activeCount(), numb_threads) # Test enabled alarm with no repeats alarm.repeat = (False, False, False, False, False, False, False) alarm.enabled = True launch_success = alarm_mgr._AlarmManager__set_alarm_thread(alarm) self.assertFalse(launch_success) self.assertEqual(threading.activeCount(), numb_threads) # Test fully active alarm alarm.wednesday = True launch_success = alarm_mgr._AlarmManager__set_alarm_thread(alarm) self.assertTrue(launch_success) self.assertGreater(threading.activeCount(), numb_threads)
Example #19
Source File: test_threading_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_str_name(self): t = Thread(name=1) self.assertEqual(t.getName(), '1') t.setName(2) self.assertEqual(t.getName(), '2') # make sure activeCount() gets decremented (see issue 1348)
Example #20
Source File: test_threading.py From android_universal with MIT License | 5 votes |
def test__all__(self): extra = {"ThreadError"} blacklist = {'currentThread', 'activeCount'} support.check__all__(self, threading, ('threading', '_thread'), extra=extra, blacklist=blacklist)
Example #21
Source File: test_threading.py From android_universal with MIT License | 5 votes |
def test_old_threading_api(self): # Just a quick sanity check to make sure the old method names are # still present t = threading.Thread() t.isDaemon() t.setDaemon(True) t.getName() t.setName("name") with self.assertWarnsRegex(PendingDeprecationWarning, 'use is_alive()'): t.isAlive() e = threading.Event() e.isSet() threading.activeCount()
Example #22
Source File: counters.py From FCR with MIT License | 5 votes |
def register_counters(cls, stats_mgr): stats_mgr.register_counter("sessions", CommandSession.get_session_count) stats_mgr.register_counter("gc.garbage", lambda: len(gc.garbage)) stats_mgr.register_counter("active_threads", threading.activeCount) stats_mgr.register_counter( "cpu_usage_permille", lambda: round(cls._getCpuUsage() * 10) )
Example #23
Source File: main.py From AutoHookSpider with GNU General Public License v3.0 | 5 votes |
def run(self,*args): if args: self.entrances = args[0].split(',') for i in self.entrances: self.q.put('http://{}'.format(i)) else: print '[+] Choose Entrances Domain ing ...' self.entrances = random.sample(self.hooks,self.thread_cnt) for i in self.entrances: if not port(i,80): self.reSelect(i) else: self.q.put('http://{}'.format(i)) print "[+] Use : {}".format('、'.join(self.entrances)) for t in xrange(self.thread_cnt): t = threading.Thread(target=self.req) t.setDaemon(True) t.start() while True: if threading.activeCount() <= 1: break else: try: time.sleep(0.1) except KeyboardInterrupt: self.STOP_ME = True raise
Example #24
Source File: __init__.py From ActiveReign with GNU General Public License v3.0 | 5 votes |
def main(args, config_obj, db_obj, loggers): lockout_obj = LockoutTracker(args, loggers) servers = { 'smb' : smb_server_setup(args, loggers['console']), 'http' : http_server_setup(args, loggers['console']) } active_threads = [] for target in args.target: try: t = threading.Thread(target=thread_launcher, args=(target, args, lockout_obj, config_obj, db_obj, loggers,)) t.daemon = True t.start() active_threads.append(t) while threading.activeCount() > args.max_threads: sleep(0.001) for t in active_threads: if not t.isAlive(): active_threads.remove(t) except KeyboardInterrupt: print("\n[!] Key Event Detected, Closing...") exit(0) except Exception as e: loggers['console'].debug(args.debug, "Enum-Main: {}".format(str(e))) # Cleanup & Close while len(active_threads) > 0: for t in active_threads: if not t.isAlive(): active_threads.remove(t) sleep(0.01) for server,obj in servers.items(): if obj: obj.cleanup_server() os._exit(0) # Only realy way ive found to shutdown server
Example #25
Source File: lambda_load_test.py From invokust with MIT License | 5 votes |
def start_new_thread(self): """ Creates a new load test thread """ t_name = "thread_{0}".format(threading.activeCount()) t = threading.Thread(name=t_name, target=self.thread) t.daemon = True t.start()
Example #26
Source File: test_threading_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_str_name(self): t = Thread(name=1) self.assertEqual(t.getName(), '1') t.setName(2) self.assertEqual(t.getName(), '2') # make sure activeCount() gets decremented (see issue 1348)
Example #27
Source File: test_threading_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_activeCount(self): activeBefore = threading.activeCount() activeCount = 10 for i in range(activeCount): t = Thread(target=self._sleep, args=(i,)) t.setDaemon(0) t.start() polls = activeCount while activeCount > activeBefore and polls > 0: time.sleep(1) activeCount = threading.activeCount() polls -= 1 self.assertTrue(activeCount <= activeBefore, 'activeCount should to be <= %s, instead of %s' % (activeBefore, activeCount))
Example #28
Source File: test_threading_jy.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_activeCount(self): activeBefore = threading.activeCount() activeCount = 10 for i in range(activeCount): t = Thread(target=self._sleep, args=(i,)) t.setDaemon(0) t.start() polls = activeCount while activeCount > activeBefore and polls > 0: time.sleep(1) activeCount = threading.activeCount() polls -= 1 self.assertTrue(activeCount <= activeBefore, 'activeCount should to be <= %s, instead of %s' % (activeBefore, activeCount))
Example #29
Source File: SpiderEntry.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def proxy_updator(): global proxy_object while True: if proxy_object.get_proxy_num()<10: print "当前线程数",threading.activeCount() print "正在添加代理",proxy_object.get_proxy_num() proxy_object.add_more_proxyip()#此线程陷入阻塞,但不影响其他线程对代理的获取 else: #print "代理充足",proxy_object.get_proxy_num() sleep(1) #负责拿到输入域名集
Example #30
Source File: __init__.py From ActiveReign with GNU General Public License v3.0 | 5 votes |
def main(args, config_obj, db_obj, loggers): for passwd in args.passwd: # Indicate start if args.hash: loggers['console'].info("\033[1;30mPerforming Password Spray @ {} [Users: {}] [Hash: True] [Method: {}]\033[0m".format(get_timestamp(), len(args.user), args.method)) else: loggers['console'].info("\033[1;30mPerforming Password Spray @ {} [Users: {}] [Password: {}] [Method: {}]\033[0m".format(get_timestamp(),len(args.user), passwd, args.method)) # Start for target in args.target: for user in args.user: # Last minute adjustments to spray values if args.combo: user, passwd = user.split(':') if args.user_as_pass: passwd = user.strip() elif args.hash: passwd = '' # Create new namespace to pass to spray handler auth_args = Namespace(user = user, passwd = passwd, hash = args.hash, domain = args.domain, local_auth = args.local_auth, debug = args.debug, timeout = args.timeout, method = args.method, mode = args.mode, user_as_pass = args.user_as_pass, jitter = args.jitter ) t= Thread(target=spray, args=(auth_args, loggers, db_obj, config_obj, target, user, passwd,)) t.daemon=True t.start() while activeCount() > args.max_threads: sleep(0.001) while activeCount() > 1: sleep(0.001)