if (counter == 20): print("1 euro") if (counter == 30): print("2 euro") counter = 0 count = 1 print("Ready to process the next payment !") time.sleep(1) def thirdFunction(): global ts while True: if (counting == 0): ts = time.time() time.sleep(1) try: t1 = Thread(target=firstFunction) t2 = Thread(target=secondFunction) t3 = Thread(target=thirdFunction) t1.start() t2.start() t3.start() except KeyboardInterrupt: t1.stop() t2.stop() t3.Stop() GPIO.cleanup()