<s> from __future__ import print_function <EOL> import os <EOL> import time <EOL> import threading <EOL> import warnings <EOL> from klaus import make_app <EOL> class _ : <EOL> inner_app = None <EOL> should_reload = True <EOL> def poll_for_changes ( interval , dir ) : <EOL> """<STR_LIT>""" <EOL> old_contents = os . listdir ( dir ) <EOL> while <NUM_LIT:1> : <EOL> time . sleep ( interval ) <EOL> if _ . should_reload : <EOL> continue <EOL> new_contents = os . listdir ( dir ) <EOL> if new_contents != old_contents : <EOL> old_contents = new_contents <EOL> _ . should_reload = True <EOL> def make_autoreloading_app ( repos_root , * args , ** kwargs ) : <EOL> def app ( environ , start_response ) : <EOL> if _ . should_reload : <EOL> print ( "<STR_LIT>" ) <EOL> _ . inner_app = make_app ( <EOL> [ os . path . join ( repos_root , x ) for x in os . listdir ( repos_root ) ] , <EOL> * args , ** kwargs <EOL> ) <EOL> _ . should_reload = False <EOL> return _ . inner_app ( environ , start_response ) <EOL> poller_thread = threading . Thread ( target = ( lambda : poll_for_changes ( <NUM_LIT:10> , repos_root ) ) ) <EOL> poller_thread . daemon = True <EOL> poller_thread . start ( ) <EOL> return app <EOL> if '<STR_LIT>' in os . environ : <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning ) <EOL> if '<STR_LIT>' in os . environ : <EOL> with open ( os . environ [ '<STR_LIT>' ] ) as file : <EOL> application = make_autoreloading_app ( <EOL> os . environ . get ( '<STR_LIT>' ) or os . environ [ '<STR_LIT>' ] , <EOL> os . environ [ '<STR_LIT>' ] , <EOL> os . environ . get ( '<STR_LIT>' ) , <EOL> file , <EOL> ) <EOL> else : <EOL> application = make_autoreloading_app ( <EOL> os . environ . get ( '<STR_LIT>' ) or os . environ [ '<STR_LIT>' ] , <EOL> os . environ [ '<STR_LIT>' ] , <EOL> os . environ . get ( '<STR_LIT>' ) , <EOL> ) </s>
