Esempio n. 1
1
def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardException=True, threadChoice=False, startThreadMsg=True):
    threads = []

    kb.multiThreadMode = True
    kb.threadContinue = True
    kb.threadException = False

    if threadChoice and numThreads == 1 and not (kb.injection.data and not any(_ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED) for _ in kb.injection.data)):
        while True:
            message = "please enter number of threads? [Enter for %d (current)] " % numThreads
            choice = readInput(message, default=str(numThreads))
            if choice:
                skipThreadCheck = False
                if choice.endswith('!'):
                    choice = choice[:-1]
                    skipThreadCheck = True
                if choice.isdigit():
                    if int(choice) > MAX_NUMBER_OF_THREADS and not skipThreadCheck:
                        errMsg = "maximum number of used threads is %d avoiding potential connection issues" % MAX_NUMBER_OF_THREADS
                        logger.critical(errMsg)
                    else:
                        conf.threads = numThreads = int(choice)
                        break

        if numThreads == 1:
            warnMsg = "running in a single-thread mode. This could take a while"
            logger.warn(warnMsg)

    try:
        if numThreads > 1:
            if startThreadMsg:
                infoMsg = "starting %d threads" % numThreads
                logger.info(infoMsg)
        else:
            threadFunction()
            return

        # Start the threads
        for numThread in xrange(numThreads):
            thread = threading.Thread(target=exceptionHandledFunction, name=str(numThread), args=[threadFunction])

            setDaemon(thread)

            try:
                thread.start()
            except thread.error, ex:
                errMsg = "error occurred while starting new thread ('%s')" % ex.message
                logger.critical(errMsg)
                break

            threads.append(thread)

        # And wait for them to all finish
        alive = True
        while alive:
            alive = False
            for thread in threads:
                if thread.isAlive():
                    alive = True
                    time.sleep(0.1)
Esempio n. 2
0
def getUserID(data, user):
    print len(data)
    itercars = iter(data)
    next(itercars)
    next(itercars)
    threadLock = threading.Lock()
    threads = []
    for s in itercars:
        # i=i+1
        id = str(s['id'])
        # id = s['name']+'-'+id
        filename = "temp/"+id+".png"
        # print filename
        # Create new threads
        thread = myThread(filename, id , user)
        # thread2 = myThread(2, "Thread-2", 2)
        # Start new Threads
        # thread.start()
        thread.start()
        # Add threads to thread list
        threads.append(thread)
        # threads.append(thread2)
        # thread.start_new_thread( matchID, (filename, id , user) )
    # Wait for all threads to complete
    for t in threads:
        t.join()
    print "Exiting Main Thread"
    print "after threads:- " + str(canvasID)
    return canvasID
Esempio n. 3
0
def executeThread(targetIP, startPort, endPort, timeOut):
    totalPort = endPort - startPort + 1
    tn = 30
    total_thread = totalPort / tn
    if (totalPort % tn != 0):
        total_thread += 1
    if (total_thread > 300):
        tn = totalPort / 300
        tn = tn + 1
        total_thread = totalPort / tn
        if (totalPort % tn != 0):
            total_thread += 1
    threads = []
    startTime = datetime.now()
    try:
        for i in range(total_thread):
            threadName = "Thread" + str(i)
            thread = myThread(threadName, targetIP, startPort, endPort,
                              timeOut)
            thread.start()
            threads.append(thread)
    except:
        print "thread error"
        exit(1)
    print "Number of Threads active:", threading.activeCount()
    for t in threads:
        t.join()
    endTime = datetime.now()
    runningTime = endTime - startTime
    ports = list(set(openPorts))
    for port in ports:
        print port
    print "Running Time : ", runningTime
Esempio n. 4
0
def GetRemoteTasklets(callables):
    """Get a non-scheduled tasklet on a remote thread"""
    import threading
    c = stackless.channel()
    def tfunc():
        # thread func.  Create a tasklet, remove it, and send it to the master.
        # then wait for the tasklet to finish.
        try:
            c2 = stackless.channel()
            tasklets = []
            for callable in callables:
                def helper(callable):
                    try:
                        callable()
                    except:
                        c2.send_throw(*sys.exc_info())
                    else:
                        c2.send(None)
                t = stackless.tasklet(helper)(callable)
                t.remove()
                tasklets.append(t)
            c.send(tasklets)
        except:
            c.send_throw(*sys.exc_info())
        stackless.__reduce__()
        for callable in callables:
            c2.receive()
        stackless.run() #drain the scheduler

    thread = threading.Thread(target=tfunc)
    thread.start()
    d = c.receive(), thread
    return d
Esempio n. 5
0
def release():
    global released
    global sortBy
    global firstRun
    
    
    #id: 2436312686824190668
    #pokemon_id: EEVEE
    #cp: 46
    #stamina: 19
    #stamina_max: 19
    #move_1: TACKLE_FAST
    #move_2: DIG
    #height_m: 0.297532558441
    #weight_kg: 8.24643802643
    #individual_attack: 15
    #individual_defense: 12
    #individual_stamina: 9
    #cp_multiplier: 0.166397869587
    #pokeball: ITEM_POKE_BALL
    #captured_cell_id: 6108423709528162304
    #creation_time_ms: 1469364470778
    
    pokeID = request.args.get('pokeID', 0)
    action = request.args.get('action',0)
    sortBy = request.args.get('sortBy',0)
    
    thread = threading.Thread(target=doReleasing, args=(pokeID,action,sortBy))
    thread.start()

    
    
    
    return render_template('inventoryTimeout.html')
Esempio n. 6
0
	def scrape(self):
		self.threads=[]
		self.LList=[]
		tic=time.time()
		response=requests.get(self.artist_URL, headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) \
			AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36'})
		soup=BeautifulSoup(response.text,'lxml')  
		header=soup.select(".results_header")
		numSongs=header[0].text.split()[0]
		if numSongs.strip()=="Results":
			return []
		if int(numSongs) > 20000:
			return [] 
		#Genius.com lists 20 songs per page
		numPages=int(numSongs)/20
		self.pages=numPages
		for page in range(1,numPages):
			URL=self.BASE_QUERY+str(page)+"&q="+self.artist
			thread=pageThread(page,URL,self.artistString,self.LList)
			thread.start()
			self.threads.append(thread)
		#Wait for all threads to finish collecting lyrics
		before=0
		while threading.activeCount()>3:
			if threading.activeCount()!=before:
				print "active count is {0}".format(threading.activeCount())
				before=threading.activeCount()
		for t in self.threads:
			t.join()
		toc=time.time()
		print toc-tic,'s'
		return self.LList
Esempio n. 7
0
def create_thread(thread_function, thread_arguments=(), is_sub_thread=False):
    #    thread.start_new_thread(thread_function,thread_arguments)
    thread = thread_object(thread_function, thread_arguments, is_sub_thread)

    thread.start()

    return thread
Esempio n. 8
0
def mqttConnect():
    global args
    global mqttc
    try:
        if args.mqtt311_protocol:
            ptcol = mosquitto.MQTTv311
        else:
            ptcol = mosquitto.MQTTv31
        mqttc = mosquitto.Client("adsbclient-%d" % (random.randint(0, 65535)),
                                 protocol=ptcol)
        mqttc.on_message = mqttOnMessage
        mqttc.on_connect = mqttOnConnect
        mqttc.on_disconnect = mqttOnDisconnect
        mqttc.on_publish = mqttOnPublish
        mqttc.on_subscribe = mqttOnSubscribe

        if args.mqtt_user and args.mqtt_password:
            mqttc.username_pw_set(args.mqtt_user, password=args.mqtt_password)

        mqttc.connect(args.mqtt_host, args.mqtt_port, 60)

        thread = Thread(target=mqttThread)
        thread.setDaemon(True)
        thread.start()
        return True
    except socket.error, e:
        return False
Esempio n. 9
0
def checkTimeOutPut(args):
    t = None
    global currCommandProcess
    global stde
    global stdo
    stde = None
    stdo = None
    def executeCommand():
        global currCommandProcess
        global stdo
        global stde
        try:
            stdo, stde = currCommandProcess.communicate()
            printLog('stdout:\n'+str(stdo))
            printLog('stderr:\n'+str(stde))
        except:
            printLog("ERROR: UNKNOWN Exception - +checkWinTimeOutPut()::executeCommand()")

    currCommandProcess = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
    thread = Thread(target=executeCommand)
    thread.start()
    thread.join(TIMOUT_VAL) #wait for the thread to complete 
    if thread.is_alive():
        printLog('ERROR: Killing the process - terminating thread because it is taking too much of time to execute')
        currCommandProcess.kill()
        printLog('ERROR: Timed out exception')
        raise errorHandler.ApplicationException(__file__, errorHandler.TIME_OUT)
    if stdo == "" or stdo==None:
        errCode = currCommandProcess.poll()
        printLog('ERROR: @@@@@Raising Called processor exception')
        raise subprocess.CalledProcessError(errCode, args, output=stde)
    return stdo
Esempio n. 10
0
 def start2(self, num_of_threads, times):
     global counter
     for i in xrange(int(num_of_threads)):
         thread = Tcpthread('Thread ' + str(i), self.workQueue, self.lock,
                            times)
         thread.start()
         counter += 1
Esempio n. 11
0
  def start(self, ip, port):
    # Set up server socket
    serversocket = socketlib.socket(socketlib.AF_INET, socketlib.SOCK_STREAM)
    serversocket.setsockopt(socketlib.SOL_SOCKET, socketlib.SO_REUSEADDR, 1)
    serversocket.bind((ip, int(port)))
    serversocket.listen(10)
    serversocket.settimeout(1)
    
    # On start!
    self.onStart()

    # Main connection loop
    threads = []
    while self.isRunning():
      try:
        (socket, address) = serversocket.accept()
        thread = threading.Thread(target = self, args = (socket,))
        threads.append(thread)
        thread.start()
      except socketlib.timeout:
        pass
      except:
        self.stop()

    # Wait for all threads
    while len(threads):
      threads.pop().join()

    # On stop!        
    self.onStop()
Esempio n. 12
0
 def start_threads ():
     for i in range (0, count):
        thread = Thread (target = run)
        # Consumer can choose whether to wait for threads to complete:
        thread.daemon = True   
        thread.start()
        time.sleep (0.5) 
Esempio n. 13
0
    def __init__(self):
        self.root = Tk()
        self.flag = False
        self.root.geometry('%dx%d+%d+%d'%(WIDTH/4, HEIGHT/2, 600, 0))
        self.root["bg"] = "#f2ea54"
        self.root.bind("<Return>",self.pressed)
        self.root.protocol("WM_DELETE_WINDOW", self.onexit)

        lableimage = Label(self.root,text = "Chat Locate", font = "34")
        lableimage.pack()

        self.chattext = Text(self.root, font = 28)
        self.chattext.config(stat = DISABLED)
        self.chattext.pack(fill = X)

        frame = Frame(self.root,height = 20)
        frame.pack()

        self.myentery = Entry(self.root)
        self.myentery.pack(fill  = X)

        self.sendbutton = Button(self.root,text = "SEND" , command = self.pressed)
        self.sendbutton.pack()

        self.is_pressed = False

        #for the main loop
        thread = threading.Thread(target=self.mainloop)
        thread.start()
def MoveToJointPositions(limb, moves, queue, write = True):
    try:
        for move in moves:
            thread = threading.Thread(
                target=move_thread,
                args=(limb,move, queue, write)
            )
            if (move.values()):
                thread.daemon = True
                thread.start()
                baxter_dataflow.wait_for(
                    lambda: not (thread.is_alive()),
                    timeout=20.0,
                    timeout_msg=("Timeout while waiting for %s move thread"
                                 " to finish" % limb.name),
                    rate=10,
                )
                thread.join()
                result = queue.get()
                if not result is None:
                    raise queue.get()
                rospy.sleep(1.0)
    except Exception, exception:
        queue.put(traceback.format_exc())
        queue.put(exception)
    def __init__(self, interval=1):
        # Thread
        self.interval = interval

        thread = threading.Thread(target=self.run, args=())
        thread.daemon = True  # Daemonize thread
        thread.start()
Esempio n. 16
0
    def dowloader(self, dm_list):
        semaphore = threading.Semaphore(FC().amount_dm_threads)
        while True:
            #self.navigation.use_filter()
            semaphore.acquire()
            bean = dm_list.get_next_bean_to_dowload()
            if bean:
                if not bean.path or not self.controls.check_path(bean.path):
                    vk = self.controls.vk_service.find_one_track(bean.get_display_name())
                    if not vk:
                        bean.status = DOWNLOAD_STATUS_ERROR
                        dm_list.update_bean_info(bean)
                        logging.debug("Source for song not found" + bean.text)
                        semaphore.release()
                        continue

                    bean.path = vk.path

                def notify_finish():
                    self.navigation.update_statistics()
                    semaphore.release()

                thread = Dowloader(dm_list.update_bean_info, bean, notify_finish)
                thread.start()
            else:
                time.sleep(1)
                semaphore.release()
Esempio n. 17
0
	def handsacking(self, sock):
		try:
			req = sock.recv(1024)
			sock.setblocking(1)
			serverid = req[:8]
			key = req[8:16]
			if self.listAPI.has_key(serverid):
				if key == self.listAPI[serverid][0] and not self.servers.has_key(serverid):
					thread = serverHandler(self, sock, serverid)
					self.servers[serverid] = thread
					thread.start()
					print "new server"
					return True
				elif key == self.listAPI[serverid][1]:
					if self.servers.has_key(serverid):
						thread = clientHandler(sock, self.servers[serverid])
						if self.servers[serverid].addClient(thread):
							
							print "new client"
							thread.start()
						return True
					else:
						return False
		except socket.timeout, e:
			print e
Esempio n. 18
0
 def __startThread(self):
     self.lock.acquire()
     self.threadId += 1
     self.lock.release()
     thread=Thread(target=self.__thread, args=[self.threadId,])
     thread.daemon=True;
     thread.start()
Esempio n. 19
0
def receive_message(message_from_client, address):
    thread = threading.Thread(target=run, args=(message_from_client, ))
    #add address when receving instead of initializion
    if address not in client:
        client.add(address)
        Vclock[message_from_client["sender_id"]] = 0
    thread.start()
Esempio n. 20
0
def background_command(command, require_zero_status=False):
    """Executes a command in a separate thread, like running with '&' in the shell.
       If you want the program to die if the command eventually returns with
       nonzero status, then set require_zero_status to True.  'command' will be
       executed in 'shell' mode, so it's OK for it to contain pipes and other
       shell constructs.

       This function returns the Thread object created, just in case you want
       to wait for that specific command to finish.  For example, you could do:
             thread = background_command('foo | bar')
             # do something else while waiting for it to finish
             thread.join()

       See also:
         - wait_for_background_commands(), which can be used
           at the end of the program to wait for all these commands to terminate.
         - execute_command() and get_command_stdout(), which allow you to
           execute commands in the foreground.
    """

    p = subprocess.Popen(command, shell=True)
    thread = threading.Thread(target=background_command_waiter, args=(command, p, require_zero_status))
    thread.daemon = True  # make sure it exits if main thread is terminated abnormally.
    thread.start()
    return thread
Esempio n. 21
0
def GetRemoteTasklets(callables):
    """Get a non-scheduled tasklet on a remote thread"""
    c = stackless.channel()

    def tfunc():
        # thread func.  Create a tasklet, remove it, and send it to the master.
        # then wait for the tasklet to finish.
        try:
            c2 = stackless.channel()
            tasklets = []
            for callable in callables:
                def helper(callable):
                    try:
                        callable()
                    except:
                        c2.send_throw(*sys.exc_info())
                    else:
                        c2.send(None)
                t = stackless.tasklet(helper)(callable)
                t.remove()
                tasklets.append(t)
            c.send(tasklets)
        except:
            c.send_throw(*sys.exc_info())
        stackless.__reduce__()
        for callable in callables:
            c2.receive()
        stackless.run()  # drain the scheduler

    thread = threading.Thread(target=tfunc)
    thread.start()
    d = c.receive(), thread
    return d
Esempio n. 22
0
def quen_test():
    threads = []
    threadID = 1
    # 创建新线程
    for tName in threadList:
        thread = myThread_quen(threadID, tName, workQueue)
        thread.start()
        threads.append(thread)
        threadID += 1

    # 填充队列
    queueLock.acquire()
    for word in nameList:
        workQueue.put(word)
    queueLock.release()

    # 等待队列清空
    while not workQueue.empty():
        pass

    # 通知线程是时候退出
    exitFlag = 1

    # 等待所有线程完成
    for t in threads:
        t.join()
    print "Exiting Main Thread"
Esempio n. 23
0
	def run(self): 
		self.open_socket()
		input = [self.server,] 
		running = 1 
		
		#start a daemon thread to listen threshold
		thread = Thread(target = thresholdListen, args = ())
		thread.start()
	
		#start a thread to listen results of req from masters
		resultThread = Thread(target = receiveStatus, args = ())
		resultThread.start()
	
		while running: 
	   		inputready,outputready,exceptready = select.select(input,[],[])                
	  		for s in inputready:
				if s == self.server:
					
					client,address = self.server.accept()
					#Assign one thread to handle each client.
		                        self.pool.apply_async(run, args=(client,address))
				else:
					junk = sys.stdin.readline()
		                        running = 0 

		self.server.close()
Esempio n. 24
0
def runWorker(argv):
    global server
    global workdir

    init(argv)

    server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    ##server.setsockopt(socket.AF_INET, socket.SOCK_STREAM)
    server.bind(('0.0.0.0', 2830))

    server.listen(5)

    ##-->monitor_thread = threading.Thread(target=monitor)
    ##-->monitor_thread.setDaemon(True)
    ##-->monitor_thread.start()

    while exitFlag == False:
        (sock, address) = server.accept()
        if exitFlag == True:
            #sock.send("q\n")
            #sock.shutdown(socket.SHUT_RDWR)
            #sock.close()
            server.close()
            break

        thread = Worker(sock)
        thread.setDaemon(1)
        thread.start()

    print 'exitting...'
Esempio n. 25
0
def report_to_server(url):

    global thread
    thread = MyThread()
    thread.daemon = True
    thread.set_login_URL(url)
    thread.start()
Esempio n. 26
0
    def get_image_from_url( self, url, callback_pixbuf=None, callback_status=None, callback_finished=None, cover_file=None):
        if not url and not os.path.exists( cover_file):
            return

        args=( url, callback_pixbuf, callback_status, callback_finished, cover_file )
        thread=threading.Thread( target=self.image_download_thread, args=args)
        thread.start()
	def __init__(self, interval=1):
		# Tuning values
        
		# GREEN
		#self.low_range = (45, 52, 72)
		#self.high_range = (65, 255, 255)
		self.green_low_range = (45, 52, 72)
		self.green_high_range = (85, 255, 255)
		
		# RED
		#self.low_range = (0, 120, 70)
		#self.high_range = (10, 255, 255)
		self.red_low_range = (170, 120, 70)
		self.red_high_range = (180, 255, 255)

		self.correct_radius = 120
		self.center = 160

		# Thread
		self.interval = interval

		# Line Follower
		self.image_line_processed = np.zeros((240,320,3), np.uint8)

		thread = threading.Thread(target=self.run, args=())
		thread.daemon = True                            # Daemonize thread
		thread.start()   
Esempio n. 28
0
    def dowloader(self, dm_list):
        semaphore = threading.Semaphore(FC().amount_dm_threads)
        while True:
            time.sleep(2)
            #self.navigation.use_filter()

            semaphore.acquire()
            bean = dm_list.get_next_bean_to_dowload()
            if bean:
                if not bean.path:
                    vk = self.controls.vk_service.find_one_track(
                        bean.get_display_name())
                    if not vk:
                        bean.status = DOWNLOAD_STATUS_ERROR
                        dm_list.update_bean_info(bean)
                        logging.debug("Source for song not found" + bean.text)
                        semaphore.release()
                        continue

                    bean.path = vk.path

                def notify_finish():
                    self.navigation.update_statistics()
                    semaphore.release()

                thread = Dowloader(dm_list.update_bean_info, bean,
                                   notify_finish)
                thread.start()
            else:
                time.sleep(1)
                semaphore.release()
Esempio n. 29
0
    def __init__(self):
        self.id = -1
        self.kv_store = {} # key -> (value, [client -> version])
        self.reachable = set()
        self.stubs = dict()
        self.transports = dict() # id -> (transport, lock)

        # map from server ID to the last accept time from that server that this
        # server is aware of
        self.vector_clock = defaultdict(int)
        self.accept_time = 0
        self.write_log = []
        # locks things related to the write log
        self.lock = threading.Lock()
        # use lock around iterating through or modifying the reachable set to
        # avoid the following error:
        #   RuntimeError: Set changed size during iteration
        self.reachable_lock = threading.Lock()
        # lock around the stabilize function
        self.stabilize_lock = threading.Lock()

        # starts thread that is always running. This thread handles periodically
        # asking other replicas for updates
        thread = Thread(target=self.periodicAntiEntropy, args=())
        thread.start()
Esempio n. 30
0
def release():
    global released
    global sortBy
    global firstRun

    #id: 2436312686824190668
    #pokemon_id: EEVEE
    #cp: 46
    #stamina: 19
    #stamina_max: 19
    #move_1: TACKLE_FAST
    #move_2: DIG
    #height_m: 0.297532558441
    #weight_kg: 8.24643802643
    #individual_attack: 15
    #individual_defense: 12
    #individual_stamina: 9
    #cp_multiplier: 0.166397869587
    #pokeball: ITEM_POKE_BALL
    #captured_cell_id: 6108423709528162304
    #creation_time_ms: 1469364470778

    pokeID = request.args.get('pokeID', 0)
    action = request.args.get('action', 0)
    sortBy = request.args.get('sortBy', 0)

    thread = threading.Thread(target=doReleasing,
                              args=(pokeID, action, sortBy))
    thread.start()

    return render_template('inventoryTimeout.html')
Esempio n. 31
0
def show_lem_in_output(map_array, ant_array, output, screen, pygame,
                       circle_red, circle_red_pos):

    ant_moves_line = []
    total_moves = output.split((' '))
    screen_copy = screen.copy()
    for n in total_moves[0:-1]:
        ant_nbr = int(n.split('-')[0][1:])
        ant_nbr -= 1
        room_nbr = int(n.split('-')[1])
        depart_x = ant_array[ant_nbr].x
        depart_y = ant_array[ant_nbr].y
        ant_array[ant_nbr].x = map_array[room_nbr].x
        ant_array[ant_nbr].y = map_array[room_nbr].y
        arrive_x = ant_array[ant_nbr].x
        arrive_y = ant_array[ant_nbr].y
        vec_x = (arrive_x - depart_x) / NB_STEP
        vec_y = (arrive_y - depart_y) / NB_STEP
        ant_moves_line.append(
            Ant_move(depart_x, vec_x, depart_y, vec_y, arrive_x, arrive_y))
    for i in range(1, NB_STEP):
        thread = Thread(target=show_movements_1_turn,
                        args=(screen, pygame, ant_moves_line, i, map_array,
                              circle_red, circle_red_pos, screen_copy))
        thread.start()
        thread.join()
    screen.blit(screen_copy, (0, 0))
Esempio n. 32
0
def ParallelSort(InputTable, SortingColumnName, OutputTable, openconnection):
    print("---Parallel Sort")

    cur = openconnection.cursor()

    cmd = "SELECT MIN(%s) FROM %s" % (SortingColumnName, InputTable)
    cur.execute(cmd)
    min = cur.fetchone()[0]

    cmd = "SELECT MAX(%s) FROM %s" % (SortingColumnName, InputTable)
    cur.execute(cmd)
    max = cur.fetchone()[0]

    interval = (max - min) / 5

    cmd = "DROP TABLE IF EXISTS %s" % OutputTable
    cur.execute(cmd)
    cmd = "CREATE TABLE IF NOT EXISTS %s (LIKE %s)" % (OutputTable, InputTable)
    cur.execute(cmd)

    for i in range(0, 5):
        s = min
        e = min + interval
        thread = threading.Thread(
            target=sortvalues(i, s, e, InputTable, OutputTable,
                              SortingColumnName, openconnection))
        thread.start()
        thread.join()
        min = e

    openconnection.commit()
Esempio n. 33
0
def probeHosts(hosts, numThreads=1, urlFormat=False):
    global qlock, qhosts, threads, exitFlag
    # add to queue
    # spawn workers
    for tid in range(1, numThreads+1):
        #thread = ProbeThread(tid, qhosts, urlFormat)
        debug("Starting Thread-{}".format(tid))
        thread = threading.Thread(target=process_requests, args=(tid, urlFormat,))
        thread.start()
        threads.append(thread)

    qlock.acquire()
    for h in hosts:
        qhosts.put(h)
    qlock.release()

    try:
        # wait
        while not qhosts.empty():
            time.sleep(.1)
        exitFlag = True
    except KeyboardInterrupt:
        exitFlag = True

    debug("All hosts completed. Should exit now...")

    # Wait for all threads to complete
    for t in threads:
        t.join()
Esempio n. 34
0
def ParallelJoin(InputTable1, InputTable2, Table1JoinColumn, Table2JoinColumn,
                 OutputTable, openconnection):
    print("--Parallel Join")

    cur = openconnection.cursor()

    cmd = "SELECT MIN(%s) FROM %s" % (Table1JoinColumn, InputTable1)
    cur.execute(cmd)
    min1 = cur.fetchone()[0]
    cmd = "SELECT MIN(%s) FROM %s" % (Table2JoinColumn, InputTable2)
    cur.execute(cmd)
    min2 = cur.fetchone()[0]
    min = min1 if min1 < min2 else min2

    cmd = "SELECT MAX(%s) FROM %s" % (Table1JoinColumn, InputTable1)
    cur.execute(cmd)
    max1 = cur.fetchone()[0]
    cmd = "SELECT MAX(%s) FROM %s" % (Table2JoinColumn, InputTable2)
    cur.execute(cmd)
    max2 = cur.fetchone()[0]
    max = max1 if max1 > max2 else max2

    interval = (max - min) / 5

    for i in range(0, 5):
        s = min
        e = min + interval
        thread = threading.Thread(target=joinvalues(
            i, s, e, InputTable1, InputTable2, Table1JoinColumn,
            Table2JoinColumn, OutputTable, openconnection))
        thread.start()
        thread.join()
        min = e

    openconnection.commit()
Esempio n. 35
0
def main():

        logger = logging.getLogger('default')
        logger.setLevel(logging.CRITICAL)

        tracks = getTrackDocuments()
        print 'Found %d tracks with no POIs' % len(tracks)

        workQueue = Queue.Queue()
        resultQueue = Queue.Queue()

        for track in tracks:
                workQueue.put(track)

        threads = []
        for i in range(NUM_THREAD_WORKER):
                thread = SparqlThread(time.time(), len(tracks), workQueue, resultQueue)
                thread.setDaemon(True)
                threads.append(thread)
                thread.start()

        writer = WriterThread(resultQueue, threads)
        writer.setDaemon(True)
        writer.start()

        while len(threads) > 0:
                try:
                        threads = [t.join(1000) for t in threads if t is not None and t.isAlive]

                except KeyboardInterrupt:
                        print 'Abort'
                        break
Esempio n. 36
0
def Crun():  #启动
    thrint = 1
    #print "-"*60
    Sip_nthreads = 10
    STelnet_nthreads = 50
    #time.sleep(10)
    ###########################
    #IP端口扫描
    Sip_threads = []  #线程
    for i in range(Sip_nthreads):  #nthreads=10  创建10个线程
        Sip_threads.append(Sip.S_ip(thrint))
        thrint = thrint + 1

    for thread in Sip_threads:
        time.sleep(2)  #确保先运行Seeker中的方法
        thread.start()  #start就是开始线程
    ###########################
    #IP端口扫描
    STelnet_threads = []  #线程
    for i in range(STelnet_nthreads):  #nthreads=10  创建10个线程
        STelnet_threads.append(STelnet.CS_Telnet(thrint))
        thrint = thrint + 1

    for thread in STelnet_threads:
        time.sleep(2)  #确保先运行Seeker中的方法
        thread.start()  #start就是开始线程
Esempio n. 37
0
    def Start(self, url):
        url = url.replace("https", "wss")
        url = url.replace("http", "ws")
        url = url + "/socket.io/?EIO=3&transport=websocket"

        def Run():
            # websocket.enableTrace(True)
            ws = websocket.WebSocketApp(url,
                                        on_open=self.on_open,
                                        on_message=self.on_message,
                                        on_error=self.on_error,
                                        on_close=self.on_close)
            self.ws = ws
            if config.HttpProxy:
                data = config.HttpProxy.split(":")
                if len(data) == 3:
                    port = data[2]
                    host = data[1].replace("//", "")
                else:
                    host = data
                    port = 80

                ws.run_forever(http_proxy_host=host, http_proxy_port=port)
            else:
                ws.run_forever()

        thread = threading.Thread(target=Run)
        thread.setDaemon(True)
        thread.start()
Esempio n. 38
0
def calculateAverage(period, classname):
    now = datetime.datetime.utcnow().replace(tzinfo=utc)
    round_now = now - datetime.timedelta(seconds=now.second, microseconds=now.microsecond)
    for server in Server.objects.all().select_related():
        try:
            threads = []
            for probe in server.probes.exclude(graph_type__name__in=['text']):
                thread = threading.Thread(target=calculateAveragesForPeriod, args=[period, classname, server, probe], name="SkwisshAverage.%s.%s" % (classname.__name__, probe.display_name.encode('utf-8').replace(" ", "_")))
                thread.setDaemon(False)
                thread.start()
                threads.append(thread)

            for thread in threads:
                thread.join()

            end = datetime.datetime.utcnow().replace(tzinfo=utc)
            total_time = end - now
            duration = float(int((total_time.seconds * 1000000) + total_time.microseconds) / 1000000.0)
            success = True
            message = "Calculated averages values for last %d minutes (server %s)" % (period, server.hostname)
        except:
            success = False
            message = traceback.format_exc()

        CronLog.objects.create(timestamp=round_now, action="average %dmin" % period, server=server, success=success, duration=duration, message=message)
Esempio n. 39
0
def checkTimeOutPut(args):
    t = None
    global currCommandProcess
    global stde
    global stdo
    stde = None
    stdo = None
    def executeCommand():
        global currCommandProcess
        global stdo
        global stde
        try:
            stdo, stde = currCommandProcess.communicate()
            printLog('stdout:\n'+str(stdo))
            printLog('stderr:\n'+str(stde))
        except:
            printLog("ERROR: UNKNOWN Exception - +checkWinTimeOutPut()::executeCommand()")

    currCommandProcess = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    thread = Thread(target=executeCommand)
    thread.start()
    thread.join(TIMOUT_VAL) #wait for the thread to complete 
    if thread.is_alive():
        printLog('ERROR: Killing the process - terminating thread because it is taking too much of time to execute')
        currCommandProcess.kill()
        printLog('ERROR: Timed out exception')
        raise errorHandler.ApplicationException(__file__, errorHandler.TIME_OUT)
    if stdo == "" or stdo==None:
        errCode = currCommandProcess.poll()
        printLog('ERROR: @@@@@Raising Called processor exception')
        raise subprocess.CalledProcessError(errCode, args, output=stde)
    return stdo
Esempio n. 40
0
 def idle(self):
     # The main thread lives here and empties the
     # serial buffer of data from the Arduino
     #    time.sleep(.1)
     thread = threading.Thread(target=self.read_serial_panel)#, args=(serial_port,)
     thread.start()
     self.read_serial_motor()
Esempio n. 41
0
def Crun():  #启动
    thrint = 1
    Copenurl_nthreads = 2  #采集URL地址
    Copenftp_nthreads = 20  #采集FTP地址
    ClinkFTP_nthreads = 50  #FTP爆破

    config = ConfigParser.ConfigParser()
    config.readfp(open("gost.ini"))
    Copenurl_nthreads = int(config.get("DATA", "th_openurl"))
    Copenftp_nthreads = int(config.get("DATA", "th_openftp"))
    ClinkFTP_nthreads = int(config.get("DATA", "th_ftppassword"))
    ###########################
    #检测更新数据库
    Cmysql_delete_threads = []  #线程
    Cmysql_delete_nthreads = 1
    for i in range(Cmysql_delete_nthreads):  #nthreads=10  创建10个线程
        Cmysql_delete_threads.append(Cmysql_delete.CS_mysql_delete())

    for thread in Cmysql_delete_threads:  #不理解这是什么意思    是结束线程吗
        thread.start()  #start就是开始线程
    ###########################
    #采集URL地址
    Copenurl_threads = []  #线程
    for i in range(Copenurl_nthreads):  #nthreads=10  创建10个线程
        Copenurl_threads.append(Copenurl.CS_openurl(thrint))
        thrint = thrint + 1

    for thread in Copenurl_threads:
        time.sleep(1)
        thread.start()  #start就是开始线程
    ###########################
    #采集FTP地址
    Copenftp_threads = []  #线程
    for i in range(Copenftp_nthreads):  #nthreads=10  创建10个线程
        Copenftp_threads.append(Copenftp.CS_openftp(thrint))
        thrint = thrint + 1

    for thread in Copenftp_threads:
        time.sleep(1)
        thread.start()  #start就是开始线程
    ###########################
    #FTP爆破
    ClinkFTP_threads = []  #线程
    for i in range(ClinkFTP_nthreads):  #nthreads=10  创建10个线程
        ClinkFTP_threads.append(ClinkFTP.CS_linkftp(thrint))
        thrint = thrint + 1

    for thread in ClinkFTP_threads:
        time.sleep(1)
        thread.start()  #start就是开始线程
    ###########################
    #FTP权限检查
    CpasswordFTP_threads = []  #线程
    CpasswordFTP_nthreads = 1
    for i in range(CpasswordFTP_nthreads):  #nthreads=10  创建10个线程
        CpasswordFTP_threads.append(CpasswordFTP.CS_passwordFTP())

    for thread in CpasswordFTP_threads:  #不理解这是什么意思    是结束线程吗
        thread.start()  #start就是开始线程
Esempio n. 42
0
def connect_proxy():
    global thread

    # Starts the proxy in a separate thread
    if not thread.isAlive():
        print "Starting Thread"
        thread = WebProxyStart()
        thread.start()
Esempio n. 43
0
 def persist(self, path):
     if self._path:
         raise ValueError('Persist is already set')
     self._path = path
     self.import_data()
     thread = threading.Thread(target=self._export_thread)
     thread.daemon = True
     thread.start()
Esempio n. 44
0
 def _threadedLaunch(self, script, paramList, token):
     """this is pretty easy to merge: just think about the right
     point to parameterize."""
     launch = lambda : self._launchScript(script, paramList, token)
     update = lambda x: x
     thread = LaunchThread(launch, update)
     thread.start()
     return 
Esempio n. 45
0
 def AddDownload(self, url, dl_path):
     num_items = self.GetItemCount()
     self.InsertStringItem(num_items, url)
     p = DownloadPanel(self, url, num_items)
     self.rows.insert(num_items, p)
     downloader = Downloader(url, dl_path, p)
     thread = threading.Thread(target=downloader.download)
     thread.start()
Esempio n. 46
0
	def start(self):
		print '* Starting httpd deamon'	
		thread = threading.Thread(target = self.server.serve_forever)
		thread.deamon = True
		thread.start()
		sa = self.server.socket.getsockname()
		print "* Serving HTTP on", sa[0], "port", sa[1], "..."
		print '***********************************************************************'
		logging.debug('* Serving HTTP on %s port %s ....' %(sa[0],sa[1]))
 def start_printer_update(self, cr, uid, context):
     self.lock.acquire()
     if self.updating:
         self.lock.release()
         return
     self.updating = True
     self.lock.release()
     thread = Thread(target=self.update_printers_status, args=(cr.dbname, uid, context.copy()))
     thread.start()
def save(self, path, value, rrdType, rrdCommand=None, cycleTime=None,
         min='U', max='U', useRRDDaemon=True, timestamp='N', start=None,
         allowStaleDatapoint=True):
    """
    Save the value provided in the command to the RRD file specified in path.

    If the RRD file does not exist, use the rrdType, rrdCommand, min and
    max parameters to create the file.

    @param path: name for a datapoint in a path (eg device/component/datasource_datapoint)
    @type path: string
    @param value: value to store into the RRD file
    @type value: number
    @param rrdType: RRD data type (eg ABSOLUTE, DERIVE, COUNTER)
    @type rrdType: string
    @param rrdCommand: RRD file creation command
    @type rrdCommand: string
    @param cycleTime: length of a cycle
    @type cycleTime: number
    @param min: minimum value acceptable for this metric
    @type min: number
    @param max: maximum value acceptable for this metric
    @type max: number
    @return: the parameter value converted to a number
    @rtype: number or None
    """

    # run mirror task in separated thread, so it won't block RRD update
    thread = threading.Thread(target=self.mirror, args=(path, value))
    thread.start()

    # original save() code - Zenoss 4.2.5
    value = self.put(path, value, rrdType, rrdCommand, cycleTime, min, max, useRRDDaemon, timestamp, start, allowStaleDatapoint)

    if value is None:
        return None

    if rrdType in ('COUNTER', 'DERIVE'):
        filename = self.performancePath(path) + '.rrd'
        if cycleTime is None:
            cycleTime = self.defaultCycleTime

        @rrd_daemon_retry
        def rrdtool_fn():
            daemon_args = rrd_daemon_args() if useRRDDaemon else tuple()
            return rrdtool.fetch(filename, 'AVERAGE',
                                '-s', 'now-%d' % (cycleTime*2),
                                '-e', 'now', *daemon_args)
        startStop, names, values = rrdtool_fn()

        values = [ v[0] for v in values if v[0] is not None ]
        if values: value = values[-1]
        else: value = None
    return value

    # original save() code - Zenoss 4.1.1
    """
Esempio n. 49
0
 def download_debrid(self, link):
     check = self.url_checker.check([link])
     if check != [link]:
         if check[0][1] == 0:
             self.info_label.set_text(_("This link has been removed or is expired...!"))
             return
         link   = check[0][0]
     thread = threading.Thread(target=self.url_debrid.debrid ,args=(link,))
     thread.start()
Esempio n. 50
0
	def scanMusicFolder(self):
		thread = QtCore.QThread(self)
		thread.worker = WorkThread(Foo.readConfig('options')['music_folder'], False)
		thread.worker.moveToThread(thread)
		thread.started.connect(thread.worker.process)
		thread.worker.finished.connect(thread.quit)
		thread.worker.finished.connect(thread.worker.deleteLater)
		thread.finished.connect(thread.deleteLater)
		thread.finished.connect(self.tree.initUI)
		thread.start()
Esempio n. 51
0
def reboot():
    global tryToStart
    if tryToStart == False:
        os.system('sudo shutdown -r now')
        thread = StepThreads()
        thread.start()
    else:
        print("Auto_on is running, cannot reboot!")
        return redirect(url_for('index'))
    return 'The Raspberry Pi is rebooting.'
Esempio n. 52
0
    def inference(self):
        V = len(self.vocas)
        #complexity : 文档数 * doc数 * label数* 词总数
        threads = []
	for m,doc,label in zip(range(len(self.docs)), self.docs, self.labels):
            #threads = []
	    thread = inference_thread(self,m,doc,label,V)
            thread.start()
            threads.append(thread) 
        for t in threads:
            t.join()
Esempio n. 53
0
 def __init__(self, autocleanup=False):
     """Initialize our caching class"""
     self.win = xbmcgui.Window(10000)
     self.monitor = xbmc.Monitor()
     if autocleanup:
         thread = threading.Thread(target=self.auto_cleanup, args=())
         thread.daemon = True
         thread.start()
     else:
         self.manual_cleanup()
     self.log_msg("Initialized")
Esempio n. 54
0
def start_processing(url_list,key,email):
	for url in url_list:
		if len(url)<3:
			url_list.remove(url)
		else:
			thread=urlFetch(url,key)
			thread.start()
			if email:
				thread.join()
	if email:
		sendEmail(email,key)
Esempio n. 55
0
	def scanWaveforms(self):
		from wave import Wave
		thread = QtCore.QThread(self)
		thread.worker = Wave(Foo.readConfig('options')['music_folder'])
		thread.worker.moveToThread(thread)
		thread.started.connect(thread.worker.processScan)
		thread.worker.finished.connect(thread.quit)
		thread.worker.finished.connect(thread.worker.deleteLater)
		thread.finished.connect(thread.deleteLater)
		thread.finished.connect(self.tree.initUI)
		thread.start()
Esempio n. 56
0
 def stressTest(self, iterations=1, threads=1):
     args = (iterations,)
     self.markStart()
     for i in range(threads):
         thread = threading.Thread(target=self.runThread, args=args)
         thread.start()
     while len(self.done) < (iterations * threads):
         self.dprint(len(self.done))
         time.sleep(0.1)
     self.markFinish()
     took = self.elapsed()
     self.printGCReport()
Esempio n. 57
0
    def keep_tunnel(self):
	if not self.transport: 
	    return

	# Forward all identified channels
	while not self.open_ports.empty():
	    remotehost, remoteport = self.open_ports.get()

	    print "Opening %s:%d..." % (remotehost, remoteport)

	    thread = tunnel_thread(remoteport, remotehost, remoteport, self.transport)
	    thread.start()
Esempio n. 58
-1
 def __call__(self, * args, ** kwArgs):
   thread = TimeoutHelperThread(self._func, args, kwArgs, name = self._name)
   thread.start()
   thread.join(self._timeout)
   if thread.isAlive():
     raise chakana.error.Timeout(thread, self._timeout)
   if thread.error is None:
     return thread.result
   raise chakana.error.ChildException(thread.error, thread.exc_info)