Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use WSGI server #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-

# required for python-prctl
RUN apt-get update && apt-get install -y libcap-dev && rm -rf /var/lib/apt/lists/*

ADD . /app/
RUN pip3 install virtualenv \
&& virtualenv --always-copy /app/env \
&& /app/env/bin/pip3 install paver

# install requirements.txt stuff in an earlier layer
# this is just to speed up local builds in dev
ADD requirements.txt /app/
RUN /app/env/bin/pip3 install -r requirements.txt

ADD . /app/
RUN /app/env/bin/paver install_deps

CMD /app/env/bin/python3 /app/sideboard/run_server.py
EXPOSE 8282

2 changes: 2 additions & 0 deletions development-defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ws.auth_required = False

[cherrypy]
server.socket_host = "0.0.0.0"
server.socket_port = "8282"
server.thread_pool = "30"
engine.autoreload.on = True
tools.cpstats.on = False

Expand Down
1 change: 1 addition & 0 deletions sideboard/configspec.ini
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ profiling.strip_dirs = boolean(default=False)

server.socket_host = string(default="127.0.0.1")
server.socket_port = integer(default=8282)
server.thread_pool = integer(default=30)

tools.reset_threadlocal.on = boolean(default=True)

Expand Down
1 change: 1 addition & 0 deletions sideboard/run_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
import sideboard.server

if __name__ == '__main__':
# Start the server engine (Option 1 *and* 2)
cherrypy.engine.start()
cherrypy.engine.block()
14 changes: 14 additions & 0 deletions sideboard/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def check_authentication(cls):
'tools.staticdir.dir': os.path.join(config['module_root'], 'docs', 'html'),
'tools.staticdir.index': 'index.html'
}

cherrypy_config = {}
for setting, value in config['cherrypy'].items():
if isinstance(value, six.string_types):
Expand All @@ -155,6 +156,19 @@ def check_authentication(cls):
cherrypy_config[setting] = value
cherrypy.config.update(cherrypy_config)

# Unsubscribe the default server
cherrypy.server.unsubscribe()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably need to delve into the cherrypy source code to figure out why we're doing this. Regardless, it would be useful to add a comment here explaining why. You have several comments explaining what you're doing, but I find "why" comments to be a lot more useful. In particular, "Unsubscribe the default server" doesn't tell me anything about the purpose of this code or what it's actually accomplishing. I'm pretty sure that we were already able to set server.socket_host and such in our config file, so I'm unclear what this code is doing.


# Instantiate a new server object
server = cherrypy._cpserver.Server()

# Configure the server object
server.socket_host = config['cherrypy']['server.socket_host']
server.socket_port = config['cherrypy']['server.socket_port']
server.thread_pool = config['cherrypy']['server.thread_pool']

# Subscribe this server
server.subscribe()

# on Python 2, we need bytestrings for CherryPy config, see https://bitbucket.org/cherrypy/cherrypy/issue/1184
def recursive_coerce(d):
Expand Down