python类activeCount()的实例源码

thfcgi.py 文件源码 项目:pypi-legacy 作者: pypa 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def run(self):
        """Wait & serve. Calls request_handler on every request."""
        self.sock.listen(self.backlog)
        log("Starting Process")
        running = True
        while running:
            if not self.requests_left:
                # self.sock.shutdown(RDWR) here does NOT help with backlog
                running = False
            elif self.requests_left > 0:
                self.requests_left -= 1
            if running:
                conn, addr = self.sock.accept()
                threadcount = _threading.activeCount()
                if threadcount < self.max_threads:
                    log("Accepted connection, starting thread...")
                    t = _threading.Thread(target=self.accept_handler, args=(conn, addr, True))
                    t.start()
                else:
                    log("Accepted connection, running in main-thread...")
                    self.accept_handler(conn, addr, False)
                log("Active Threads: %d" % _threading.activeCount())
        self.sock.close()
        log("Ending Process")
F-Scrack.py 文件源码 项目:F-Scrack 作者: y1ng1996 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
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
http_dispatcher.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def to_string(self):
        worker_rate = {}
        for w in self.workers:
            worker_rate[w] = w.get_rtt_rate()

        w_r = sorted(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 rtt:%d a:%d live:%d processed:%d" % \
                       (w.ip, w.rtt, w.accept_task, (time.time()-w.ssl_sock.create_time), w.processed_tasks)
            if w.version == "2":
                out_str += " streams:%d ping_on_way:%d\r\n" % (len(w.streams), w.ping_on_way)

            out_str += " Speed:"
            for speed in w.speed_history:
                out_str += "%d," % speed

            out_str += "\r\n"

        return out_str
http_dispatcher.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def to_string(self):
        worker_rate = {}
        for w in self.workers:
            worker_rate[w] = w.get_rtt_rate()

        w_r = sorted(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 rtt:%d a:%d live:%d processed:%d" % \
                       (w.ip, w.rtt, w.accept_task, (time.time()-w.ssl_sock.create_time), w.processed_tasks)
            if w.version == "2":
                out_str += " streams:%d ping_on_way:%d\r\n" % (len(w.streams), w.ping_on_way)

            out_str += " Speed:"
            for speed in w.speed_history:
                out_str += "%d," % speed

            out_str += "\r\n"

        return out_str
admin.py 文件源码 项目:ProfSnoo 作者: snoonetIRC 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def sysinfo(prefix, chan, params):

    seconds = time.time() - bot.start_time

    times = []

    days = seconds // 86400
    hours = seconds // 3600 % 24
    minutes = seconds // 60 % 60
    seconds = seconds % 60

    if days: times.append('%s days' % int(days))
    if hours: times.append('%s hours' % int(hours))
    if minutes: times.append('%s minutes' % int(minutes))
    if seconds: times.append('%s seconds' % int(seconds))

    bot.say(chan, 'Uptime: %s Threads: %s' % (
        ', '.join(times),
        threading.activeCount()
        ))
test_threadpool.py 文件源码 项目:assetsweeper 作者: guardian 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_scaledown(self):
        """
        test that a thread pool will scale down properly
        :return:
        """
        pool = self.ThreadPool(TestThread, initial_size=10, keywordarg="keywordstring")

        try:
            self.assertEqual(threading.activeCount(), 11)
            pool.scale_down(timeout=1)
            self.assertEqual(threading.activeCount(), 10)
            pool.scale_down(timeout=1)
            self.assertEqual(threading.activeCount(), 9)
            pool.scale_down(timeout=1)
            self.assertEqual(threading.activeCount(), 8)
            pool.scale_down(timeout=1)
            self.assertEqual(threading.activeCount(), 7)
            pool.scale_down(timeout=1)
        finally:
            pool.safe_terminate()
http_dispatcher.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def to_string(self):
        worker_rate = {}
        for w in self.workers:
            worker_rate[w] = w.get_rtt_rate()

        w_r = sorted(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 rtt:%d a:%d live:%d processed:%d" % \
                       (w.ip, w.rtt, w.accept_task, (time.time()-w.ssl_sock.create_time), w.processed_tasks)
            if w.version == "2":
                out_str += " streams:%d ping_on_way:%d\r\n" % (len(w.streams), w.ping_on_way)

            out_str += " Speed:"
            for speed in w.speed_history:
                out_str += "%d," % speed

            out_str += "\r\n"

        return out_str
smarthome.py 文件源码 项目:smarthome 作者: smarthomeNG 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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
    #################################################################
subDomainsBrute.py 文件源码 项目:python_pen 作者: RASSec 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _load_dns_servers(self):
        print '[+] Initializing, validate DNS servers ...'
        self.dns_servers = []
        with open('dict/dns_servers.txt') as f:
            for line in f:
                server = line.strip()
                if not server:
                    continue
                while True:
                    if threading.activeCount() < 50:
                        t = threading.Thread(target=self._test_server, args=(server,))
                        t.start()
                        break
                    else:
                        time.sleep(0.1)

        while threading.activeCount() > 2:
            time.sleep(0.1)
        self.dns_count = len(self.dns_servers)
        sys.stdout.write('\n')
        print '[+] Found %s available DNS servers in total' % self.dns_count
F-Scrack.py 文件源码 项目:VulScript 作者: y1ng1996 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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
subDomainsBrute.py 文件源码 项目:00scanner 作者: xiaoqin00 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _load_dns_servers(self):
        print '[+] Initializing, validate DNS servers ...'
        self.dns_servers = []
        with open('./subDomain/dict/dns_servers.txt') as f:
            for line in f:
                server = line.strip()
                if not server:
                    continue
                while True:
                    if threading.activeCount() < 50:
                        t = threading.Thread(target=self._test_server, args=(server,))
                        t.start()
                        break
                    else:
                        time.sleep(0.1)

        while threading.activeCount() > 2:
            time.sleep(0.1)
        self.dns_count = len(self.dns_servers)
        sys.stdout.write('\n')
        print '[+] Found %s available DNS Servers in total' % self.dns_count
        if self.dns_count == 0:
            print '[ERROR] No DNS Servers available.'
            self.STOP_ME = True
            sys.exit(-1)
weakPassCracker.py 文件源码 项目:00scanner 作者: xiaoqin00 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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
game_functions.py 文件源码 项目:Alien_Python 作者: flowerland 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def check_bullet_alien_collisions(ai_settings,screen,stats,sb,ship,
    aliens,bullets):
    collisions = pygame.sprite.groupcollide(bullets,aliens,True,True)
    if collisions:
        for aliens in collisions.values():
            stats.score += ai_settings.alien_points * len(aliens)
            sb.prep_score()
        check_high_score(stats,sb)
    #lock.acquire()
    if len(aliens) == 0 and threading.activeCount() == 1:
        #print(threading.activeCount())
        #print(threading.currentThread().getName() + " start")
        bullets.empty()
        ai_settings.increase_speed()
        #????
        stats.level += 1
        sb.prep_level()
        #create_fleet(0,ai_settings,screen,ship,aliens)
        for i in range(4):
            t =threading.Thread(target=create_fleet,args=(i,ai_settings,screen,ship,aliens))
            t.start()
        #print(threading.currentThread().getName() + " end")
    #lock.release()
http_dispatcher.py 文件源码 项目:XX-Net-Mini 作者: GFWParty 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def to_string(self):
        worker_rate = {}
        for w in self.workers:
            worker_rate[w] = w.get_rtt_rate()

        w_r = sorted(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 rtt:%d a:%d live:%d processed:%d" % \
                       (w.ip, w.rtt, w.accept_task, (time.time()-w.ssl_sock.create_time), w.processed_tasks)
            if w.version == "2":
                out_str += " streams:%d ping_on_way:%d\r\n" % (len(w.streams), w.ping_on_way)

            out_str += " Speed:"
            for speed in w.speed_history:
                out_str += "%d," % speed

            out_str += "\r\n"

        return out_str
recipe-286240.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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
recipe-578193.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def run(self):
        try:
            url,filename=self.qu1.get()
            url =url+self.ad             #comment this line in case need to download whole web page instead of recipe ONLY...
            ul.urlretrieve(url,filename)
            global count
        except:
            print " RE-TRYING ",
            count= count - 1
            self.qu1.put((url,filename))
            self.run()
        finally:
            count= count +1
            print str(count)+"("+str( threading.activeCount())  +")",filename
            self.qu1.task_done()
pyscan.py 文件源码 项目:darkc0de-old-stuff 作者: tuwid 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
main.py 文件源码 项目:AutoHookSpider 作者: Tr3jer 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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
q_mapper.py 文件源码 项目:cadee 作者: kamerlinlab 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def q_map(self):
        # Creates threads that call q_mapsingle() on each directory (replica)
        # returns a tuple (mapped_directories, failed_directories)

        self._mapped = []
        self._failed = []

        trs = []
        for md in self._map_dirs:
            num = threading.activeCount() - 1     #    -1: one thread is the main thread
            while num == self._nthreads:
                time.sleep(0.3)
                num = threading.activeCount() - 1     # -1:    one thread is the main thread
            if num < self._nthreads:
                trs.append( _Mapthread(self, md) )
                trs[-1].start()

        # wait for threads to finish, save their response
        for t in trs:
            while t.isAlive():
                t.join(1.0)
            if t.error:
                self._failed.append( (t.path, t.error) )
            else:
                self._mapped.append( t.path )

        if not self._mapped:
            errstr=""
            for m,er in self._failed:
                errstr += "%s -> %s\n" % (os.path.relpath(m), er)
            raise QMappingError("All %s directories failed to map!\n%s" % ( len(self.get_mapdirs()), errstr) )

        return (self._mapped, self._failed)
test_threading.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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")
        t.isAlive()
        e = threading.Event()
        e.isSet()
        threading.activeCount()
duckling.py 文件源码 项目:python-duckling 作者: FraBle 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self,
                 jvm_started=False,
                 parse_datetime=False,
                 minimum_heap_size='128m',
                 maximum_heap_size='2048m'):
        """Initializes Duckling.
        """

        self.parse_datetime = parse_datetime
        self._is_loaded = False
        self._lock = threading.Lock()

        if not jvm_started:
            self._classpath = self._create_classpath()
            self._start_jvm(minimum_heap_size, maximum_heap_size)

        try:
            # make it thread-safe
            if threading.activeCount() > 1:
                if jpype.isThreadAttachedToJVM() is not 1:
                    jpype.attachThreadToJVM()
            self._lock.acquire()

            self.clojure = jpype.JClass('clojure.java.api.Clojure')
            # require the duckling Clojure lib
            require = self.clojure.var("clojure.core", "require")
            require.invoke(self.clojure.read("duckling.core"))
        finally:
            self._lock.release()
counters.py 文件源码 项目:FCR 作者: facebookincubator 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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))
test_threadpool.py 文件源码 项目:assetsweeper 作者: guardian 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_new_threadpool(self):
        """
        test that a thread pool starts up correctly, and safely terminate
        :return:
        """
        pool = self.ThreadPool(TestThread,initial_size=1,keywordarg="keywordstring")

        self.assertEqual(threading.activeCount(),2)
        pool.safe_terminate()
test_threadpool.py 文件源码 项目:assetsweeper 作者: guardian 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_scaleup(self):
        """
        test that a thread pool will scale up properly
        :return:
        """
        pool = self.ThreadPool(TestThread, initial_size=1, keywordarg="keywordstring")

        try:
            self.assertEqual(threading.activeCount(), 2)
            pool.scale_up()
            self.assertEqual(threading.activeCount(), 3)
            pool.scale_up()
            self.assertEqual(threading.activeCount(), 4)
        finally:
            pool.safe_terminate()
SpiderEntry.py 文件源码 项目:Malicious_Domain_Whois 作者: h-j-13 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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)

#?????????
BuiltinWebServer.py 文件源码 项目:OKUSON 作者: frankluebeck 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def StartServer(port = 8000):
    '''Starts the server.'''
    global SERVER
    server_address = ('',port)
    httpd = BuiltinWebServer(server_address, WebServerRequestHandler)
    SERVER = httpd
    # We need the following two to be able to interrupt the accept
    # call, such that the server really terminates:
    SERVER.ourpid = os.getpid()
    signal.signal(signal.SIGUSR1,sigusr1handler)   # handle signal USR1
    while not(SERVER.raus):
        try:
          httpd.handle_request()
        except:
          Utils.Error("Exception in handle_request: ", prefix="Info: ")
          etype, value, tb = sys.exc_info()
          lines = traceback.format_exception(etype,value,tb)
          Utils.Error(string.join(lines),prefix="")
          pass
    Utils.Error("Waiting for threads to terminate...", prefix="Info: ")
    wait = TERMWAIT
    while threading.activeCount() > 1 and wait > 0:
        time.sleep(1)
        wait = wait - 1
    if httpd.restartcommand != '':
      # for freeing the port the new server will listen
      Utils.Error("Restarting...", prefix="Info: ")
      httpd.server_close()
      os.execl(httpd.restartcommand, httpd.restartcommand)
    Utils.Error("Terminating...", prefix="Info: ")


# finally, we add here a few more WebResponse classes of general interest

# a WebResponse with a cached result
test_threading.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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")
        t.isAlive()
        e = threading.Event()
        e.isSet()
        threading.activeCount()
thread-back.py 文件源码 项目:astoptool 作者: zouliuyun 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def execThread(sshObj,cmd,result,ip):
    result[ip] = sshObj.cmd(cmd)
    #print "cmd theading count:%d"%threading.activeCount()
#def putThread(sshObj,file,remote_path='.',recursive=False, preserve_times=False):
thread-back.py 文件源码 项目:astoptool 作者: zouliuyun 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def sshConn(ip,servers):
    check = False
    for i in range(10):
        try:
            servers[ip] = ssh.ssh(ip)
            check = True
            break
        except:
            time.sleep(1)
            print "connect server %s try again ..."%ip
    if not check:
        print "connect server %s failed!"%ip
    #print "ssh theading count:%d"%threading.activeCount()
vipiapp.py 文件源码 项目:obsoleted-vpduserv 作者: InfraSIM 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def main_loop(self):
        rlist = []
        rlist.append(self.__pipe.inform)
        timeout = 10
        print "Total threads: {0}".format(threading.activeCount())
        try:
            while self.__running:
                readable, _, _ = select.select(rlist, [], [], timeout)
                if not readable:
                    continue

                if self.__pipe.inform in readable:
                    try:
                        message = self.__pipe.read(256)
                    except OSError, exc:
                        logger.warn("[Error %d] appeared at reading pipe" %
                                    exc.errno)
                        continue

                    if len(message) == 0:
                        continue

                    pdu_id = message.split()[0].split('.')[-2]
                    pdu_index = self.to_index(int(pdu_id))
                    logger.info("Assign message to pdu {0}".format(pdu_id))
                    self.__pdus[pdu_index].handle_message(message)
        except KeyboardInterrupt:
            logger.error("Break by user.")
        except Exception, ex:
            logger.error("{0}: {1}".format(sys._getframe().f_code.co_name, ex))
        finally:
            logger.info("vIPI Appliance service exits.")
            self.__pipe.close()


问题


面经


文章

微信
公众号

扫码关注公众号