Initial test
This commit is contained in:
26
countDownTimer.py
Normal file
26
countDownTimer.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import time
|
||||
import threading
|
||||
|
||||
def countdown_timer(countdown_time, timer_id):
|
||||
while countdown_time > 0:
|
||||
mins, secs = divmod(countdown_time, 60)
|
||||
time_format = '{:02d}:{:02d}'.format(mins, secs)
|
||||
print(f"Timer {timer_id}: {time_format}", end='\r') # Print the time remaining
|
||||
time.sleep(1) # Wait for 1 second
|
||||
countdown_time -= 1
|
||||
print(f"Timer {timer_id}: Cek status mesin")
|
||||
|
||||
# Create multiple countdown timers
|
||||
timer1 = threading.Thread(target=countdown_timer, args=(10, 1))
|
||||
timer2 = threading.Thread(target=countdown_timer, args=(15, 2))
|
||||
timer3 = threading.Thread(target=countdown_timer, args=(20, 3))
|
||||
|
||||
# Start the timers
|
||||
timer1.start()
|
||||
timer2.start()
|
||||
timer3.start()
|
||||
|
||||
# Wait for all timers to complete
|
||||
timer1.join()
|
||||
timer2.join()
|
||||
timer3.join()
|
||||
Reference in New Issue
Block a user