pgadmin4/web/pgAdmin4.py
Murtuza Zabuawala d202366a5d Fixes #1185 - While connecting to the server, application becomes almost
inaccessible.

In stand (without threaded) mode, flask application is not able to
process more than one request at a time. Hence - even the client
(browser) send multiple request, when connecting the server (which is
inaccessible), rest of operations get blocked, as making the connection
with the database server is blocking operation.

In order to fix the issue, we're starting the application with thread
support, in which it will create a separate thread of each request.
2016-06-02 14:51:33 +05:30

82 lines
2.9 KiB
Python

##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
"""This is the main application entry point for pgAdmin 4. If running on
a webserver, this will provide the WSGI interface, otherwise, we're going
to start a web server."""
import os
import sys
# We need to include the root directory in sys.path to ensure that we can
# find everything we need when running in the standalone runtime.
root = os.path.dirname(os.path.realpath(__file__))
if sys.path[0] != root:
sys.path.insert(0, root)
import config
from pgadmin import create_app
##########################################################################
# Sanity checks
##########################################################################
# Check for local settings if running in server mode
if config.SERVER_MODE is True:
local_config = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'config_local.py')
if not os.path.isfile(local_config):
print("The configuration file %s does not exist.\n" % local_config)
print("Before running this application, ensure that config_local.py has been created")
print("and sets values for SECRET_KEY, SECURITY_PASSWORD_SALT and CSRF_SESSION_KEY")
print("at bare minimum. See config.py for more information and a complete list of")
print("settings. Exiting...")
sys.exit(1)
# Check if the database exists. If it does not, create it.
if not os.path.isfile(config.SQLITE_PATH):
setupfile = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'setup.py')
execfile(setupfile)
##########################################################################
# Server starup
##########################################################################
# Create the app!
app = create_app()
if config.DEBUG:
app.debug = True
else:
app.debug = False
# Start the web server. The port number should have already been set by the
# runtime if we're running in desktop mode, otherwise we'll just use the
# Flask default.
if 'PGADMIN_PORT' in globals():
app.logger.debug('PGADMIN_PORT set in the runtime environment to %s',
globals()['PGADMIN_PORT'])
server_port = int(globals()['PGADMIN_PORT'])
else:
app.logger.debug(
'PGADMIN_PORT is not set in the runtime environment, using default of %s',
config.DEFAULT_SERVER_PORT)
server_port = config.DEFAULT_SERVER_PORT
try:
app.run(
host=config.DEFAULT_SERVER,
port=server_port,
use_reloader=(config.SERVER_MODE and app.debug),
threaded=config.THREADED_MODE
)
except IOError:
app.logger.error("Error starting the app server: %s", sys.exc_info())