import os import stat import time # the amount of time, in seconds, before a channel is considered inactive INACTIVITY_TIME = 3600 # create global variable for message timestamp: # Timestamp contains the last time a message of this type was seen try: Timestamp except NameError: # if Timestamp does not exist, define it Timestamp = time.time() # check whether this channel has been inactive def checkForInactivity(): global Timestamp CurrentTime = time.time() Delta = int(CurrentTime - Timestamp) if Delta > INACTIVITY_TIME: # print warning message - channel has restarted LastString = time.strftime( '%Y-%m-%d %H:%M', time.localtime(Timestamp)) print "IDLE CHANNEL RESTARTED: first message since %s" % LastString # update timestamp to the time that this message came through Timestamp = CurrentTime