<s> import rpyc <EOL> import os <EOL> import time <EOL> from threading import Thread <EOL> class FileMonitorService ( rpyc . Service ) : <EOL> class exposed_FileMonitor ( object ) : <EOL> def __init__ ( self , filename , callback , interval = <NUM_LIT:1> ) : <EOL> self . filename = filename <EOL> self . interval = interval <EOL> self . last_stat = None <EOL> self . callback = rpyc . async ( callback ) <EOL> self . active = True <EOL> self . thread = Thread ( target = self . work ) <EOL> self . thread . start ( ) <EOL> def exposed_stop ( self ) : <EOL> self . active = False <EOL> self . thread . join ( ) <EOL> def work ( self ) : <EOL> while self . active : <EOL> stat = os . stat ( self . filename ) <EOL> if self . last_stat is not None and self . last_stat != stat : <EOL> self . callback ( self . last_stat , stat ) <EOL> self . last_stat = stat <EOL> time . sleep ( self . interval ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from rpyc . utils . server import ThreadedServer <EOL> ThreadedServer ( FileMonitorService , port = <NUM_LIT> ) . start ( ) </s>
