myflask.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python
  2. import requests,threading,time,json,zlib,gnupg,socket,psutil,os,sys,pymysql,queue,numpy,apsw
  3. from flask import Flask
  4. import libproxysql as ps
  5. app = Flask("proxysql")
  6. p = HttpParser()
  7. gpg=gnupg.GPG()
  8. pathname = os.path.dirname(sys.argv[0])
  9. abspath=os.path.abspath(pathname)
  10. configfile=abspath+"/config.json"
  11. try:
  12. cf=open(configfile,"r")
  13. except:
  14. cf=open(configfile+".template","r")
  15. log_conf=json.load(cf)
  16. cf.close()
  17. parameter={"device":socket.gethostname(),"allowed_ip":{"127.0.0.1":"25A4CF79414F10FD"},"gpg_keyid":"25A4CF79414F10FD"}
  18. for n in parameter:
  19. if n in log_conf:
  20. parameter[n]=log_conf[n]
  21. @app.route('/')
  22. def hello_world():
  23. return 'Hello World!'
  24. # since we're using threads, shouldn't we be able to pause execution of one?
  25. @app.route('/slow')
  26. def slow():
  27. import time
  28. time.sleep(10)
  29. return 'zzz'
  30. if __name__ == "__main__":
  31. q=Queue(maxsize=0)
  32. sql_worker=threading.Thread(target=ps.sql_insert,args=(q,))
  33. sql_worker.setDaemon(True)
  34. sql_worker.start()
  35. with open('./log', 'a+') as log:
  36. try:
  37. app.run(threaded=True)
  38. log.write("done adding wsgi app\n")
  39. except Exception, e:
  40. log.write(repr(e))