当前位置: 首页>>代码示例>>Python>>正文


Python threading.activeCount方法代码示例

本文整理汇总了Python中threading.activeCount方法的典型用法代码示例。如果您正苦于以下问题:Python threading.activeCount方法的具体用法?Python threading.activeCount怎么用?Python threading.activeCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在threading的用法示例。


在下文中一共展示了threading.activeCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:19,代码来源:plugins.py

示例2: scan

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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 
开发者ID:OffensivePython,项目名称:HeartLeak,代码行数:22,代码来源:HeartLeak.py

示例3: list_threads

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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
    ################################################################# 
开发者ID:smarthomeNG,项目名称:smarthome,代码行数:22,代码来源:smarthome.py

示例4: status

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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" 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:22,代码来源:pyssltest.py

示例5: main

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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() 
开发者ID:MisterDaneel,项目名称:pysoxy,代码行数:26,代码来源:pysoxy.py

示例6: test_set_alarm_thread_edit

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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) 
开发者ID:carlosperate,项目名称:LightUpPi-Alarm,代码行数:26,代码来源:AlarmManager_test.py

示例7: test_stop_alarm_thread

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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) 
开发者ID:carlosperate,项目名称:LightUpPi-Alarm,代码行数:20,代码来源:AlarmManager_test.py

示例8: test_stop_all_alarm_threads

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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) 
开发者ID:carlosperate,项目名称:LightUpPi-Alarm,代码行数:26,代码来源:AlarmManager_test.py

示例9: t_join

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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 
开发者ID:y1ng1996,项目名称:F-Scrack,代码行数:21,代码来源:F-Scrack.py

示例10: rid_cycling

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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) 
开发者ID:m8r0wn,项目名称:nullinux,代码行数:23,代码来源:nullinux.py

示例11: launcher

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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) 
开发者ID:m8r0wn,项目名称:enumdb,代码行数:25,代码来源:__init__.py

示例12: getInfo

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
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
    # 
开发者ID:autolab,项目名称:Tango,代码行数:21,代码来源:tango.py

示例13: run_modules

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
def run_modules():
    x = FeedModules()
    threads = []
    for i in dir(x):
        if i.endswith('_update'):
            mod = getattr(x, i)
            threads.append(Thread(target=mod, name='{}'.format(i)))
        else:
            pass

    for t in threads:
        t.start()
        print('Initialized: {}'.format(t.name))

    sleep(3)
    stat = 0.0
    total = float(len(threads))

    tcount = activeCount()
    while tcount > 1:
        stat = total - float(activeCount()) + 1.0
        prog = stat/total
        update_progress(prog)
        tcount = activeCount()
        sleep(1)
    print((Fore.GREEN + '\n[+]' + Fore.RESET + ' Feed collection finished!')) 
开发者ID:opensourcesec,项目名称:Forager,代码行数:28,代码来源:Forager.py

示例14: is_alive

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
def is_alive():
    """
    Check is only main thread is alive and if guest react.
    """
    if ((os_linux and (threading.activeCount() == 2)) or
            ((not os_linux) and (threading.activeCount() == 1))):
        print("PASS: Guest is ok no thread alive")
    else:
        threads = ""
        for thread in threading.enumerate():
            threads += thread.name + ", "
        print("FAIL: On guest run thread. Active thread:" + threads) 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:14,代码来源:virtio_console_guest.py

示例15: takeover

# 需要导入模块: import threading [as 别名]
# 或者: from threading import activeCount [as 别名]
def takeover(args, targets):
    stdout.write("\n\033[1;30m[*] Subdomain Takeover Check\033[1;m\n")
    stdout.write("\033[1;30m{:<45}\t({:<9})\t{}\033[1;m\n".format('Subdomain', 'http/https', 'CNAME Record'))
    try:
        for target in targets:
            Thread(target=takeover_check, args=(target,), daemon=True).start()
            while activeCount() > args.max_threads:
                sleep(0.001)
        while activeCount() > 1:
            sleep(0.005)
    except KeyboardInterrupt:
        stdout.write("\n[!] Key Event Detected...\n\n")
        return 
开发者ID:m8r0wn,项目名称:subscraper,代码行数:15,代码来源:__init__.py


注:本文中的threading.activeCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。