Beispiel #1
0
    def test_server_list(cls, target_list, shared_settings):
        """
        Tests connectivity with each server of the target_list and returns
        the list of online servers.
        """

        # Use a thread pool to connect to each server
        thread_pool = ThreadPool()
        for target_str in target_list:
            thread_pool.add_job((cls._test_server, (target_str, shared_settings)))

        nb_threads = min(len(target_list), cls.MAX_THREADS)
        thread_pool.start(nb_threads)

        # Return valid targets
        for (job, target) in thread_pool.get_result():
            yield target

        # Use None as a sentinel
        yield None

        # Return invalid targets
        for (job, exception) in thread_pool.get_error():
            yield exception

        thread_pool.join()
        return
def handler( ips_cmds ):
	
	taskCount = len( ips_cmds )
	if taskCount > _THREAD_NUMBER: 
		threadCount = _THREAD_NUMBER
	else: 
		threadCount = taskCount

	pool=ThreadPool(threadCount)
	for ip, cmds in ips_cmds:
		pool.addTask(telnetTask, ip = ip, cmds = cmds )
	pool.start()

	dlg = wx.ProgressDialog("Waitng", "Waiting",
                          		maximum = taskCount,
                          		parent= None,
                          		#style = wx.PD_CAN_ABORT|wx.PD_APP_MODAL
                      		)
   	while pool.getFinishCount() < taskCount:
   		dlg.Update(pool.getFinishCount(), "%d of %d" %(pool.getFinishCount(), taskCount))         
		wx.MilliSleep(100)	
	dlg.Destroy()
	
	result = pool.show()
	pool.join()#pool itself is also a thread
	return result
    def test_connectivity(self,  timeout):
        """
        Tests connectivity with each server of the target_list and returns 
        the list of online servers.
        """
        
        # Use a thread pool to connect to each server
        thread_pool = ThreadPool()
        for target_str in self._target_list:
            thread_pool.add_job((self._test_server,
                                (target_str, timeout)))
            
        nb_threads = min(len(self._target_list), self.MAX_THREADS)
        thread_pool.start(nb_threads)
        
        # Recover valid targets
        for (job, target) in thread_pool.get_result():
            self._targets_OK.append(target)
            yield target
                        
        # Store invvalid targets
        for (job, exception) in thread_pool.get_error():
            self._targets_ERR.append(exception)

        thread_pool.join()
        return   
Beispiel #4
0
    def test_connectivity(self, timeout):
        """
        Tests connectivity with each server of the target_list and returns 
        the list of online servers.
        """

        # Use a thread pool to connect to each server
        thread_pool = ThreadPool()
        for target_str in self._target_list:
            thread_pool.add_job((self._test_server, (target_str, timeout)))

        nb_threads = min(len(self._target_list), self.MAX_THREADS)
        thread_pool.start(nb_threads)

        # Recover valid targets
        for (job, target) in thread_pool.get_result():
            self._targets_OK.append(target)
            yield target

        # Store invvalid targets
        for (job, exception) in thread_pool.get_error():
            self._targets_ERR.append(exception)

        thread_pool.join()
        return