forked from hypothesis/h
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·51 lines (43 loc) · 1.61 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
from os import environ
from os.path import join
"""
If a virtual environment is active, make sure it's being used.
Globally-installed console scripts use an absolute shebang path which
prevents them from importing virtualenv packages. Detect that case here
and correct for it.
"""
try:
activate = join(environ['VIRTUAL_ENV'], 'bin', 'activate_this.py')
execfile(activate, dict(__file__=activate))
except KeyError:
pass
from pyramid.paster import bootstrap, setup_logging
cfname = environ.get('HYPO_CONF', 'development.ini')
setup_logging(cfname)
env = bootstrap(cfname)
application = env['app']
env['closer']()
if __name__ == '__main__':
"""Runs the hypothes.is server.
The value of the :envvar:`HYPO_CONF` environment variable may be a path to
a file which is interpreted as an alternative paster configuration.
When invoked from the command line, this module uses waitress or wsgiref
to serve the application. The included 'development.ini' file will launch
the server using the paste built-in server. Alternatively, this module is
also a valid gunicorn application module which can be started
via :command:`gunicorn run`.
"""
try:
from functools import partial
from waitress import serve
run = partial(serve, application, host='0.0.0.0', port=5000)
except ImportError:
from wsgiref.simple_server import make_server
run = make_server('0.0.0.0', 5000, application).serve_forever
print 'serving on http://0.0.0.0:5000'
try:
run()
except KeyboardInterrupt:
pass
print "\nTerminated."