prevent loading un-necssary modules when using a handled, thanks Paolo

This commit is contained in:
mdipierro
2020-06-22 22:39:28 -07:00
parent cf76978a39
commit fc7c1bd2de
9 changed files with 43 additions and 27 deletions
+19 -20
View File
@@ -56,19 +56,18 @@ create_missing_folders()
# set up logging for subsequent imports
import logging.config
# This needed to prevent exception on Python 2.5:
# NameError: name 'gluon' is not defined
# See http://bugs.python.org/issue1436
# attention!, the import Tkinter in messageboxhandler, changes locale ...
import gluon.messageboxhandler
logging.gluon = gluon
# so we must restore it! Thanks ozancag
import locale
locale.setlocale(locale.LC_CTYPE, "C") # IMPORTANT, web2py requires locale "C"
exists = os.path.exists
pjoin = os.path.join
# do not need fancy graphical loggers when served by handler
# (e.g. apache + mod_wsgi), speed up execution
if not global_settings.web2py_runtime_handler:
# attention!, the import Tkinter in messageboxhandler, changes locale ...
import gluon.messageboxhandler
# This needed to prevent exception on Python 2.5:
# NameError: name 'gluon' is not defined
# See http://bugs.python.org/issue1436
logging.gluon = gluon
# so we must restore it! Thanks ozancag
import locale
locale.setlocale(locale.LC_CTYPE, "C") # IMPORTANT, web2py requires locale "C"
try:
logging.config.fileConfig(abspath("logging.conf"))
@@ -76,6 +75,9 @@ except: # fails on GAE or when logfile is missing
logging.basicConfig()
logger = logging.getLogger("web2py")
exists = os.path.exists
pjoin = os.path.join
from gluon.restricted import RestrictedError
from gluon.http import HTTP, redirect
from gluon.globals import Request, Response, Session
@@ -99,17 +101,14 @@ requests = 0 # gc timer
try:
version_info = read_file(pjoin(global_settings.gluon_parent, 'VERSION'))
raw_version_string = version_info.split()[-1].strip()
global_settings.web2py_version = raw_version_string
web2py_version = global_settings.web2py_version
web2py_version = global_settings.web2py_version = version_info.split()[-1].strip()
except:
raise RuntimeError("Cannot determine web2py version")
try:
# do not need rocket nor HttpServer when served by handler
# (e.g. apache + mod_wsgi), speed up execution and save memory
if not global_settings.web2py_runtime_handler:
from gluon import rocket
except:
if not global_settings.web2py_runtime_gae:
logger.warn('unable to import Rocket')
load_routes()
+3
View File
@@ -62,6 +62,9 @@ if not os.path.isdir('applications'):
sys.path = [path] + [p for p in sys.path if not p == path]
from gluon.settings import global_settings
global_settings.web2py_runtime_handler = True
import gluon.main
wsgiref.handlers.CGIHandler().run(gluon.main.wsgibase)
+3 -1
View File
@@ -40,6 +40,9 @@ if not os.path.isdir('applications'):
sys.path = [path] + [p for p in sys.path if not p == path]
from gluon.settings import global_settings
global_settings.web2py_runtime_handler = True
import gluon.main
import gluon.contrib.gateways.fcgi as fcgi
@@ -51,7 +54,6 @@ else:
application = gluon.main.wsgibase
if SOFTCRON:
from gluon.settings import global_settings
global_settings.web2py_crontype = 'soft'
fcgi.WSGIServer(application, bindAddress='/tmp/fcgi.sock').run()
+5 -4
View File
@@ -49,14 +49,15 @@ from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
global_settings.web2py_runtime_handler = True
global_settings.web2py_runtime_gae = True
global_settings.db_sessions = True
if os.environ.get('SERVER_SOFTWARE', '').startswith('Devel'):
(global_settings.web2py_runtime, DEBUG) = \
('gae:development', True)
global_settings.web2py_runtime = 'gae:development'
DEBUG = True
else:
(global_settings.web2py_runtime, DEBUG) = \
('gae:production', False)
global_settings.web2py_runtime = 'gae:production'
DEBUG = False
import gluon.main
+2
View File
@@ -13,6 +13,8 @@ def __ExtensionFactory__():
if not os.path.isdir('applications'):
raise RuntimeError('Running from the wrong folder')
sys.path = [path] + [p for p in sys.path if not p == path]
from gluon.settings import global_settings
global_settings.web2py_runtime_handler = True
import gluon.main
import isapi_wsgi
application = gluon.main.wsgibase
+3
View File
@@ -40,6 +40,9 @@ if not os.path.isdir('applications'):
sys.path = [path] + [p for p in sys.path if not p == path]
from gluon.settings import global_settings
global_settings.web2py_runtime_handler = True
import gluon.main
+3 -1
View File
@@ -53,6 +53,9 @@ if not os.path.isdir('applications'):
sys.path = [path] + [p for p in sys.path if not p == path]
from gluon.settings import global_settings
global_settings.web2py_runtime_handler = True
import gluon.main
# uncomment one of the two imports below depending on the SCGIWSGI server installed
@@ -70,7 +73,6 @@ else:
application = wsgiapp
if SOFTCRON:
from gluon.settings import global_settings
global_settings.web2py_crontype = 'soft'
# uncomment one of the two rows below depending on the SCGIWSGI server installed
+2
View File
@@ -21,6 +21,8 @@ from gevent import monkey
monkey.patch_all()
def run(options):
from gluon.settings import global_settings
global_settings.web2py_runtime_handler = True
import gluon.main
if options.password != '<recycle>':
gluon.main.save_password(options.password, int(options.port))
+3 -1
View File
@@ -26,6 +26,9 @@ if not os.path.isdir('applications'):
sys.path = [path] + [p for p in sys.path if not p == path]
from gluon.settings import global_settings
global_settings.web2py_runtime_handler = True
import gluon.main
if LOGGING:
@@ -36,5 +39,4 @@ else:
application = gluon.main.wsgibase
if SOFTCRON:
from gluon.settings import global_settings
global_settings.web2py_crontype = 'soft'