# Playtime.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-09 File created. # 2022-12-27 Converted to Python 3. # Note that the 'ticks' value returned by the time.time() # function is a floating-point value. In my Windows PC it seems # to represent seconds since the beginning of the day 1.1.1970 # WARNING! It may be better not to run this program # for a time on your computer because the infinite # loop of the program consumes quite a lot of processing # power, and that may result in that the electronics # of your computer gets too hot. In my computer the cooling # fan of the processor starts operating immediately when # I start executing this program. from threading import Thread import time class ThreadToDisplayTicksAndTime ( Thread ) : def __init__( self ) : Thread.__init__( self ) self.must_display_ticks_and_time = True def stop_this_thread( self ) : self.must_display_ticks_and_time = False def run( self ) : loop_counter = 0 print( "\n loop_counter current_time_ticks Readable time" ) previous_time_ticks = time.time() while self.must_display_ticks_and_time == True : loop_counter += 1 current_time_ticks = time.time() if ( current_time_ticks - previous_time_ticks ) > 5.000 and \ ( int( current_time_ticks ) % 5 ) == 0 : print( "\n %d %f %s" % \ ( loop_counter, current_time_ticks, time.asctime() ), end="" ) previous_time_ticks = current_time_ticks loop_counter = 0 # The main program begins. thread_to_display_ticks_and_time = ThreadToDisplayTicksAndTime() print( "\n Press the Enter key to stop the program." ) thread_to_display_ticks_and_time.start() any_string_from_keyboard = input() thread_to_display_ticks_and_time.stop_this_thread()