def __enter__(self): """Starts the countdown""" self.timer = threading.Timer(self.timeout, self.error_function) self.timer.start()
def _start_user_timer(self): self._user_timer = threading.Timer(self._user_timeout, self._keepalive_user_socket) self._user_timer.setDaemon(True) self._user_timer.start()
def createTimer(self, duration, callback, *args, **kwargs): if self.stopped: raise RuntimeError("{} already stopped".format(self)) if not self.alive: raise RuntimeError("{} not started".format(self)) return threading.Timer(duration, self.__onTimerExpiration__, args=[callback, args, kwargs])
def test_write_write_offset(self): threading.Timer(.1, self._write_offset).start() self._write_and_assert()
def getBalance(): global balance, wallet, ducofiat, balancecurrency, balanceTimer transactions = open(resources + "Transactions.bin" ,"r+") oldcontent = (transactions).read() try: s.send(bytes("BALA", encoding='utf8')) oldbalance = balance balance = s.recv(1024).decode('utf8') if oldbalance <= 0: oldbalance = balance except: messagebox.showerror("Error","Connection to master server closed.\nWallet will be restarted.") os.execl(sys.executable, sys.executable, *sys.argv) if "." in str(balance): # Check wheter we received proper data now = datetime.datetime.now() current_time = now.strftime("%H:%M:%S") transactions = open(resources + "Transactions.bin" ,"r+") oldcontent = (transactions).read() transactions.seek(0, 0) balance = round(float(balance), 8) # Format balances balancecurrency = round(float(ducofiat) * float(oldbalance), 6) difference = round(float(balance) - float(oldbalance), 8) if difference != 0.0: # Check if balance has changed if difference >= 0: # Add prefix difference = " +" + str(difference) else: difference = " " + str(difference) transactions.write(str(current_time) + str(difference) + "\n" + oldcontent) # Write to file transactions.close() transactions = open(resources + "Transactions.bin" ,"r") # Read from file content = transactions.read().splitlines() if content[0] == "": singletransaction = "No local transactions yet\n\n\n\n\n\n" transactionslist = "No local transactions yet\n" else: singletransaction = content[0] + " \n\n\n\n\n\n" transactionslist = "Local transaction list\n" + content[0] + " DUCO \n" + content[1] + " DUCO \n" + content[2] + " DUCO \n" + content[3] + " DUCO \n" + content[4] + " DUCO \n" + content[5] + " DUCO \n" + content[6] + " DUCO \n" + content[7] + " DUCO \n" + content[8] + " DUCO \n" + content[9] + " DUCO \n" if balance == oldbalance: # Don't play animation if no change in balance pass else: # Animation wallet.title("Duino-Coin GUI Wallet ("+str(VER)+") - "+str(round(float(balance), 6))+" DUCO") label = tkinter.Label(OVERVIEW, text = str(balance)+" DUCO"+str(" ")*99, bg = str(colorA), fg = str(colorHighlight), font=("Arial", 18)).place(relx=.2, rely=.13) label = tkinter.Label(OVERVIEW, text = str(balancecurrency)+" "+str(currency)+" ", bg = str(colorA), fg = str(colorHighlight), font=("Arial", 17)).place(relx=.2, rely=.35) transactionslabel = tkinter.Label(OVERVIEW, text = str(singletransaction), bg = str(colorA), fg = str(colorHighlight), justify=LEFT, font=("Arial", 15)).place(relx=.2, rely=.82) time.sleep(0.1) label = tkinter.Label(OVERVIEW, text = str(balance)+" DUCO"+str(" ")*99, bg = str(colorA), fg = str(colorB), font=("Arial", 18)).place(relx=.2, rely=.13) label = tkinter.Label(OVERVIEW, text = str(balancecurrency)+" "+str(currency)+" ", bg = str(colorA), fg = str(colorB), font=("Arial", 17)).place(relx=.2, rely=.35) transactionslabel = tkinter.Label(OVERVIEW, text = str(singletransaction), bg = str(colorA), fg = str(colorB), justify=LEFT, font=("Arial", 15)).place(relx=.2, rely=.82) transactionslistlabel = tkinter.Label(TRANSACTIONS, text = str(transactionslist), bg = str(colorA), fg = str(colorB), justify=LEFT, font=("Arial", 15)).place(relx=.03, rely=.03) else: getBalance() # Try again balanceTimer = threading.Timer(0.3, getBalance) balanceTimer.start()