def criarArquitetura (self): try: lista_str = self.lista.split(",") try: lista = [ int(lista_str[i]) for i in xrange(len(lista_str) )] except: pygame.quit() sys.atexit() #posicao na tela (x,y) x = 25 y = 15 tamNodo = 10 rate=3 aux=0 auxLine=0 coord=list() for i in xrange(len(lista)): while lista[i] > 0: pygame.draw.circle(self.screen,self.gray, (x,y*(aux+2)), tamNodo, 0) coord.append(x) coord.append(y*(aux+2)) lista[i]-=1 aux+=rate coord.append(-1) x+=100 aux=0 i=0 index=0 while(i < len(coord)): if coord[i] != -1: i+=2 else: for aux_X in xrange(index,i,2): for aux_Y in xrange((i+1), len(coord),2 ): if coord[aux_Y] != -1: pygame.draw.line(self.screen, self.blue, (coord[aux_X]+tamNodo,coord[aux_X+1]),(coord[aux_Y]-tamNodo,coord[aux_Y+1]), 2) else: break index=i+1 i+=1 self.loopFrame() except: #pega a excecao gerada trace = traceback.format_exc() #imprime #print "Ocorreu um erro: \n",trace #salva em arquivo file("trace.log","a").write(trace)
def loopFrame(self): while True: for event in pygame.event.get(): if event.type == QUIT: try: pygame.quit() sys.atexit() except: return None #sys.exit() self.clock.tick(self.FPS) pygame.display.update()
def write_data(self): self.dump_data("alloc_data.txt") def trace_handler(frame, event, arg): __prof__.trace_tick(frame, event, arg) return trace_handler def atexit(): print("\n------------------ script exited ------------------") __prof__.write_data() sys.atexit(atexit) global __prof__ if not "__prof__" in globals(): if getenv("TREZOR_MEMPERF") == "1": __prof__ = AllocCounter() else: __prof__ = _Prof() sys.settrace(trace_handler) if isinstance(__prof__, AllocCounter): __prof__.last_alloc_count = micropython.alloc_count() import main
# test sys.atexit() function import sys try: sys.atexit except AttributeError: print("SKIP") raise SystemExit some_var = None def do_at_exit(): print("done at exit:", some_var) sys.atexit(do_at_exit) some_var = "ok" print("done before exit")
__all__ = [ "register", "unregister", ] _exitfuncs = [] import sys if hasattr(sys, "atexit"): def _exitfunc(): for f, a, k in _exitfuncs: f(*a, **k) sys.atexit(_exitfunc) def register(func, *args, **kwargs): _exitfuncs.append((func, args, kwargs)) return func def unregister(func): global _exitfuncs _exitfuncs = [(f, a, k) for f, a, k in _exitfuncs if f is not func]