<s> import sys <EOL> import daemon <EOL> import lockfile <EOL> from optparse import OptionParser <EOL> from os . path import dirname , abspath , join <EOL> pwd = abspath ( dirname ( __file__ ) ) <EOL> main_path = abspath ( join ( pwd , '<STR_LIT:..>' ) ) <EOL> sys . path . append ( main_path ) <EOL> import tornado . httpserver <EOL> import tornado . ioloop <EOL> from sample . app import application <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = OptionParser ( ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:port>" , <EOL> help = "<STR_LIT>" , default = '<STR_LIT>' ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" , default = False ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , default = main_path ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , default = main_path ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> port = int ( options . port ) <EOL> http_server = tornado . httpserver . HTTPServer ( application ) <EOL> if options . daemon is True : <EOL> pidfile_name = '<STR_LIT>' % port <EOL> pidfile = join ( options . pidfile_path , pidfile_name ) <EOL> print "<STR_LIT>" % ( pidfile ) <EOL> log_file = '<STR_LIT>' % join ( options . working_directory , pidfile_name ) <EOL> print "<STR_LIT>" % log_file <EOL> log = open ( log_file , '<STR_LIT>' ) <EOL> ctx = daemon . DaemonContext ( <EOL> stdout = log , <EOL> stderr = log , <EOL> working_directory = options . working_directory , <EOL> pidfile = lockfile . FileLock ( pidfile , threaded = False ) <EOL> ) <EOL> ctx . open ( ) <EOL> print "<STR_LIT>" % port <EOL> http_server . listen ( port ) <EOL> tornado . ioloop . IOLoop . instance ( ) . start ( ) </s>
