I have this code where it loads necessary files and prints necessary information when the server starts but inside if __name__ == "__main__":
I'm starting a background process as well then finally app.run() is executed.
My problem is after loading all and comes to the starting of background process it starts to print and load everything from beginning again. And also it does the same when the server get its first request (GET/POST). How can I make it load only once?
import web
from multiprocessing import Process
import scripts
print 'Engine Started'
# Code to load and print necessary stuff goes here...
urls = (
'/test(.*)', 'Test'
)
class Test():
def GET(self,r):
tt = web.input().t
print tt
return tt
if __name__ == "__main__":
try:
print 'Cache initializing...'
p = Process(target=scripts.initiate_cleaner)
p.start() # Starts the background process
except Exception, err:
print "Error initializing cache"
print err
app = web.application(urls, globals())
app.run()
So this loads thrice ('Engine Started' prints thrice) after starting process and requesting from localhost:8080/test?t=er
I went through this but it solves the problem in flask and I use web.py