def ShutDown(self): """Initiate shutdown Call each package's shutdown(). XXX Maybe should start own thread for shutting down? Probably collisions with active focus if pProxy is stopped from its own thread. """ self.m_bIsRunning = 0 self.intfClickstream.Shutdown() self.intfGui.Shutdown() self.intfAssocRules.Shutdown() self.intfRecommendation.Shutdown() self.intfNetwork.Shutdown() self.intfStatistics.Shutdown() self.intfProxy.ShutDown() # there is a race condition while shutting down. If too many threads wait for debug output, the logfile # might get closed by shutdown(). # quickfix: wait until DbgLock is released. Sleep one second to allow all waiting threads to re-acquire lock. while self.DbgLock.locked(): thread.sleep(1) # close logfile try: self.LogFileHandle.close() except: pass
def pop(self): ''' 如果需要的list为空 则循环返回其他list的path ''' if not self.size: #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #need to sleep for a moment #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #模仿queue的功能 睡眠3秒 thread.sleep(10000) if self.size > 0: url = self.htmldb.getCacheUrl() #print 'siteID', url.siteID self.sizes[url.siteID] -= 1 return url else: return None
def start_fission(box, player, flag=False): if flag: if game_ended(): clear_board() try: thread.sleep(5) except: pass return None if grid_memory[box][1] is None: grid_memory[box][0] += 1 grid_memory[box][1] = player text = font.render(str(grid_memory[box][0]), True, color[player]) textRect = text.get_rect() textRect.center = (grid[box][0] + 50, grid[box][1] + 50) screen.blit(text, textRect) pygame.display.update(textRect) return None if grid_memory[box][0] >= 3: get_neighbours(box) while not q.empty(): nbox = q.get() text = font.render(str(grid_memory[box][0]), True, (0, 0, 0)) textRect = text.get_rect() textRect.center = (grid[box][0] + 50, grid[box][1] + 50) screen.blit(text, textRect) pygame.display.update(textRect) grid_memory[box][0] = 0 grid_memory[box][1] = None start_fission(nbox, player, flag=True) else: if not flag and grid_memory[box][1] != player: window = Tk() window.withdraw() tkMessageBox.showerror("Error", "Invalid move!") window.mainloop() return None text = font.render(str(grid_memory[box][0]), True, (0, 0, 0)) textRect = text.get_rect() textRect.center = (grid[box][0] + 50, grid[box][1] + 50) screen.blit(text, textRect) grid_memory[box][0] += 1 grid_memory[box][1] = player text = font.render(str(grid_memory[box][0]), True, color[player]) textRect = text.get_rect() textRect.center = (grid[box][0] + 50, grid[box][1] + 50) screen.blit(text, textRect) pygame.display.update(textRect) if box in [0, 5, 30, 35] and grid_memory[box][0] > 1: get_neighbours(box) while not q.empty(): nbox = q.get() text = font.render(str(grid_memory[box][0]), True, (0, 0, 0)) textRect = text.get_rect() textRect.center = (grid[box][0] + 50, grid[box][1] + 50) screen.blit(text, textRect) pygame.display.update(textRect) grid_memory[box][0] = 0 grid_memory[box][1] = None start_fission(nbox, player, flag=True) elif (box % 6 == 0 or box % 6 == 5 or box in range(6) or box in range(30, 36)) and grid_memory[box][0] > 2: get_neighbours(box) while not q.empty(): nbox = q.get() text = font.render(str(grid_memory[box][0]), True, (0, 0, 0)) textRect = text.get_rect() textRect.center = (grid[box][0] + 50, grid[box][1] + 50) screen.blit(text, textRect) pygame.display.update(textRect) grid_memory[box][0] = 0 grid_memory[box][1] = None start_fission(nbox, player, flag=True)
def clickOk(self,okbutton ): self.okbutton.click( ) thread.sleep(3) print 'Clicked ok'
def setAlias(self,alias): # self.alias.clear() self.alias.send_keys(alias) thread.sleep(5) print 'Alias entered successflly'
def print_time(threadName, delay): count = 0 while count < 5: thread.sleep(delay) count += 1 print("%s : %s" % (threadName, time.ctime(time.time())))
self.start_thread() def send_random(msg): print "sending random for %s" % msg io.send(msg + ' ' + str(random.random())) if __name__ == '__main__': spam_socket = threading.Timer(10, send_random) #spam_socket.start() bridge = BridgeNode(lc) io.run(bridge_app, debug=True) print "hello" bridge = BridgeNode(lc) thread.sleep(5) print "random stuff" io.emit('message', str(random.random())) # class WSHandler(tornado.websocket.WebSocketHandler): # def open(self): # """ # Called when a client opens the websocket # """ # self.lc = lcm.LCM(LCM_URI) # self.thread = threading.Thread(target=self.lcm_loop) # self.thread.daemon = True # self.thread.start() # self.subscriptions = {} # def close(self):
self.start_thread() def send_random(msg): print "sending random for %s" % msg io.send(msg + " " + str(random.random())) if __name__ == "__main__": spam_socket = threading.Timer(10, send_random) # spam_socket.start() bridge = BridgeNode(lc) io.run(bridge_app, debug=True) print "hello" bridge = BridgeNode(lc) thread.sleep(5) print "random stuff" io.emit("message", str(random.random())) # class WSHandler(tornado.websocket.WebSocketHandler): # def open(self): # """ # Called when a client opens the websocket # """ # self.lc = lcm.LCM(LCM_URI) # self.thread = threading.Thread(target=self.lcm_loop) # self.thread.daemon = True # self.thread.start() # self.subscriptions = {}