I am pretty new to Python, Mod_WSGI and Bottle. My main problem is that when the process is run using Mod_WSGI I want it to load a file once on initialization. With running a script in terminal you would just use if __name__ == '__main__'
I need it to load the file once on initialization (or when first called) so that any subsequent calls to the process does not require the file to be reloaded. I am unsure of how to do this.
The following code is run whenever someone goes to the recommend page
@route('/recommend')
def recommend():
parser = OptionParser(usage="usage: %prog [options]")
parser.add_option('-f', '--file', default='data.csv', help='Specify csv file to read item data from.')
parser.add_option('-D', '--debug', action='store_true', dest='debug', help='Put bottle in debug mode.')
(options, args) = parser.parse_args()
return res.recommend(request)
How do I do the first 4 lines (ones involving parser) just on initialization so that I just need to call the res.recommend() whenever the recommend page is accessed?
Any help is appreciated, Mo