Python threading.activeCount() Examples

The following are 50 code examples for showing how to use threading.activeCount(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: pypi-legacy   Author: pypa   File: thfcgi.py    (license) View Source Project 7 votes vote down vote up
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") 
Example 2
Project: F-Scrack   Author: y1ng1996   File: F-Scrack.py    (GNU General Public License v3.0) View Source Project 6 votes vote down vote up
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 3
Project: Intranet-Penetration   Author: yuxiaokui   File: http_dispatcher.py    (license) View Source Project 6 votes vote down vote up
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 
Example 4
Project: MKFQ   Author: maojingios   File: http_dispatcher.py    (license) View Source Project 6 votes vote down vote up
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 
Example 5
Project: ProfSnoo   Author: snoonetIRC   File: admin.py    (license) View Source Project 6 votes vote down vote up
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()
        )) 
Example 6
Project: assetsweeper   Author: guardian   File: test_threadpool.py    (license) View Source Project 6 votes vote down vote up
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() 
Example 7
Project: xxNet   Author: drzorm   File: http_dispatcher.py    (license) View Source Project 6 votes vote down vote up
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 
Example 8
Project: smarthome   Author: smarthomeNG   File: smarthome.py    (license) View Source Project 6 votes vote down vote up
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 9
Project: python_pen   Author: RASSec   File: subDomainsBrute.py    (license) View Source Project 6 votes vote down vote up
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 
Example 10
Project: VulScript   Author: y1ng1996   File: F-Scrack.py    (license) View Source Project 6 votes vote down vote up
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 11
Project: 00scanner   Author: xiaoqin00   File: subDomainsBrute.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 12
Project: 00scanner   Author: xiaoqin00   File: weakPassCracker.py    (license) View Source Project 6 votes vote down vote up
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 13
Project: Alien_Python   Author: flowerland   File: game_functions.py    (license) View Source Project 6 votes vote down vote up
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() 
Example 14
Project: XX-Net-Mini   Author: GFWParty   File: http_dispatcher.py    (license) View Source Project 6 votes vote down vote up
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 
Example 15
Project: code   Author: ActiveState   File: recipe-286240.py    (MIT License) View Source Project 5 votes vote down vote up
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 16
Project: code   Author: ActiveState   File: recipe-578193.py    (MIT License) View Source Project 5 votes vote down vote up
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() 
Example 17
Project: darkc0de-old-stuff   Author: tuwid   File: pyscan.py    (GNU General Public License v3.0) View Source Project 5 votes vote down vote up
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
Project: AutoHookSpider   Author: Tr3jer   File: main.py    (license) View Source Project 5 votes vote down vote up
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 19
Project: cadee   Author: kamerlinlab   File: q_mapper.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 20
Project: zippy   Author: securesystemslab   File: test_threading.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 21
Project: python-duckling   Author: FraBle   File: duckling.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 22
Project: FCR   Author: facebookincubator   File: counters.py    (license) View Source Project 5 votes vote down vote up
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
Project: assetsweeper   Author: guardian   File: test_threadpool.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 24
Project: assetsweeper   Author: guardian   File: test_threadpool.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 25
Project: Malicious_Domain_Whois   Author: h-j-13   File: SpiderEntry.py    (license) View Source Project 5 votes vote down vote up
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 26
Project: OKUSON   Author: frankluebeck   File: BuiltinWebServer.py    (license) View Source Project 5 votes vote down vote up
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 
Example 27
Project: web_ctp   Author: molebot   File: test_threading.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 28
Project: astoptool   Author: zouliuyun   File: thread-back.py    (license) View Source Project 5 votes vote down vote up
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): 
Example 29
Project: astoptool   Author: zouliuyun   File: thread-back.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 30
Project: obsoleted-vpduserv   Author: InfraSIM   File: vipiapp.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 31
Project: crypto-arbitrager   Author: artooze   File: marketmaker.py    (license) View Source Project 5 votes vote down vote up
def new_order_notify(self, kexchange, type, maker_only=True, amount=None, price=None):
        order = super().new_order(kexchange, type, maker_only, amount, price)
        
        if order:
            # self.notify_msg(order['type'], order['price'])
            t = threading.Thread(target = self.notify_msg, args=(order['type'], order['price'],))
            t.start()
            logging.info("current has %d threads" % (threading.activeCount() - 1)) 
Example 32
Project: crypto-arbitrager   Author: artooze   File: bitstar_mm.py    (license) View Source Project 5 votes vote down vote up
def new_order_notify(self, kexchange, type, maker_only=True, amount=None, price=None):
        order = super().new_order(kexchange, type, maker_only, amount, price)
        
        if order:
            # self.notify_msg(order['type'], order['price'])
            t = threading.Thread(target = self.notify_msg, args=(order['type'], order['price'],))
            t.start()
            logging.info("current has %d threads" % (threading.activeCount() - 1)) 
Example 33
Project: kekescan   Author: xiaoxiaoleo   File: FNAScan1.bak.py    (license) View Source Project 5 votes vote down vote up
def t_join(m_count):
    tmp_count = 0
    i = 0
    while True:
        time.sleep(1)
        ac_count = threading.activeCount()
        if ac_count < m_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 34
Project: kekescan   Author: xiaoxiaoleo   File: F-NAScan.kscan.py    (license) View Source Project 5 votes vote down vote up
def t_join(m_count):
    tmp_count = 0
    i = 0
    while True:
        time.sleep(2)
        ac_count = threading.activeCount()
        if ac_count < m_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 35
Project: kekescan   Author: xiaoxiaoleo   File: FNAScan.py    (license) View Source Project 5 votes vote down vote up
def t_join(m_count):
    tmp_count = 0
    i = 0
    while True:
        time.sleep(1)
        ac_count = threading.activeCount()
        if ac_count < m_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 36
Project: ouroboros   Author: pybee   File: test_threading.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 37
Project: python_data_tools   Author: king3366ster   File: DataThreadModel.py    (license) View Source Project 5 votes vote down vote up
def getActiveCount(self):
        return threading.activeCount() - 1 
Example 38
Project: pylibs   Author: tqlihuiqi   File: multiproc_download.py    (license) View Source Project 5 votes vote down vote up
def get(self):
        """ ???? """

        if self.readBytes < self.totalBytes:
            shards = range(self.totalBytes)

            os.mkdir(self.tempdir)

            for i in range(0, self.totalBytes, self.readBytes):
                point = shards[i: i + self.readBytes]
                headers = { "Range": "bytes=%s-%s" % (point[0], point[-1]) }
                filename = os.path.join(self.tempdir, str(point[-1]))

                thread = self.threadPool.get()
                t = thread(target=self.write_to_file, args=[filename, headers])
                t.start()

            while activeCount() > 1:
                time.sleep(1)

            results = sorted(map(int, os.listdir(self.tempdir)))

            with open(self.filename, "ab") as wfd:
                for result in results:
                    f = os.path.join(self.tempdir, str(result))

                    with open(f, "rb") as rfd:
                        content = True

                        while content:
                            content = rfd.read(1024)
                            wfd.write(content)

            self.delete_temp_dir()

        else:
            self.write_to_file(filename=self.filename, useThread=False) 
Example 39
Project: libhoney-py   Author: honeycombio   File: example.py    (license) View Source Project 5 votes vote down vote up
def num_threads():
    '''add information about the number of threads currently running to the
       event'''
    return threading.activeCount()


# run factorial. libh_builder comes with some fields already populated
# (namely, "version", "num_threads", and "range") 
Example 40
Project: Chromium_DepotTools   Author: p07r0457   File: subprocess2.py    (license) View Source Project 5 votes vote down vote up
def hack_subprocess():
  """subprocess functions may throw exceptions when used in multiple threads.

  See http://bugs.python.org/issue1731717 for more information.
  """
  global SUBPROCESS_CLEANUP_HACKED
  if not SUBPROCESS_CLEANUP_HACKED and threading.activeCount() != 1:
    # Only hack if there is ever multiple threads.
    # There is no point to leak with only one thread.
    subprocess._cleanup = lambda: None
    SUBPROCESS_CLEANUP_HACKED = True 
Example 41
Project: node-gn   Author: Shouqun   File: subprocess2.py    (license) View Source Project 5 votes vote down vote up
def hack_subprocess():
  """subprocess functions may throw exceptions when used in multiple threads.

  See http://bugs.python.org/issue1731717 for more information.
  """
  global SUBPROCESS_CLEANUP_HACKED
  if not SUBPROCESS_CLEANUP_HACKED and threading.activeCount() != 1:
    # Only hack if there is ever multiple threads.
    # There is no point to leak with only one thread.
    subprocess._cleanup = lambda: None
    SUBPROCESS_CLEANUP_HACKED = True 
Example 42
Project: sdk-samples   Author: cradlepoint   File: servers.py    (license) View Source Project 5 votes vote down vote up
def _map_len(self):
            return threading.activeCount() 
Example 43
Project: python_learn   Author: jetty-guo   File: thread2.py    (license) View Source Project 5 votes vote down vote up
def run(self):#????????????
		time.sleep(5)
		print "current has %d threads\r" % (threading.activeCount() - 1)
		print 'the arg thread is:%s\r' % self.arg 
Example 44
Project: python_learn   Author: jetty-guo   File: thread1.py    (license) View Source Project 5 votes vote down vote up
def run(self):#????????????
		time.sleep(5)
		print 'the arg thread is:%s\r' % self.arg
		print "current has %d threads" % (threading.activeCount() - 1) 
Example 45
Project: python-sutime   Author: FraBle   File: sutime.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, jars=[], jvm_started=False, mark_time_ranges=False, include_range=False):
        """Initializes SUTime.
        """
        self.mark_time_ranges = mark_time_ranges
        self.include_range = include_range
        self.jars = jars
        self._is_loaded = False
        self._lock = threading.Lock()

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

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

            SUTimeWrapper = jpype.JClass(
                'edu.stanford.nlp.python.SUTimeWrapper')
            self._sutime = SUTimeWrapper(
                self.mark_time_ranges, self.include_range)
            self._is_loaded = True
        finally:
            self._lock.release() 
Example 46
Project: 00scanner   Author: xiaoqin00   File: subDomainsBrute.py    (license) View Source Project 5 votes vote down vote up
def _load_dns_servers(self):
        print '[+] Initializing, validate DNS servers ...'
        self.dns_servers = []
        # f=open('./dict/dns_servers.txt','a')
        with open('./dns_servers.txt') as f:
        # f=['114.114.114.114','114.114.115.115','180.76.76.76','223.5.5.5','223.6.6.6']
            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) 
Example 47
Project: subDomainsBrute   Author: 0xa-saline   File: sub_domains_brute.py    (license) View Source Project 5 votes vote down vote up
def _load_dns_servers(self):
        print('[+] Initializing, validate DNS servers ...')
        self.dns_servers = []
        thread_list = []
        # with open('dict/dns_servers.txt') as f:
        with open('api/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.setDaemon(True)
                        t.start()
                        thread_list.append(t)
                        break
                    else:
                        time.sleep(0.1)

        while True:
            flag_finished = True
            for i in thread_list:
                if i.isAlive():
                    flag_finished = False
            if flag_finished:
                break
            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) 
Example 48
Project: kbe_server   Author: xiaohaoppy   File: test_threading.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 49
Project: BigBrotherBot-For-UrT43   Author: ptitbigorneau   File: __init__.py    (license) View Source Project 5 votes vote down vote up
def tearDown(self):
        self.console.working = False
        self.console.wait_for_threads()
        sys.stdout.write("\tactive threads count : %s " % threading.activeCount())
#        sys.stderr.write("%s\n" % threading.enumerate()) 
Example 50
Project: scraper   Author: ultraeric   File: Session.py    (license) View Source Project 5 votes vote down vote up
def run(self):
		"""Runs the queue, goes through all of the actions and their recursive definitions."""
	
		threads = []
		for i in range(self.num_threads):
			threads.append(_Action_Queue_Thread(name = '_Action_Queue_Thread' + str(i), action_queue = self))
		for thread in threads:
			thread.start()
		print(threading.activeCount())	
		for thread in threads:
			thread.join()