Skip to content
Browse files

gevent/gunicorn and some cosmetics

  • Loading branch information...
1 parent acf2f24 commit ef8facbc2c8e4d4bff5c4cc9cc0538c21aac46f1 @jacobandreas committed
Showing with 46 additions and 22 deletions.
  1. +1 −1 Procfile
  2. +5 −3 server.py → app.py
  3. +3 −0 completer.py
  4. +3 −0 requirements.txt
  5. +8 −0 static/css/style.css
  6. +3 −3 static/index.html
  7. +23 −15 static/js/autocomplete.js
View
2 Procfile
@@ -1 +1 @@
-web: python server.py
+web: gunicorn -w 4 -b 0.0.0.0:$PORT -k gevent app:app
View
8 server.py → app.py
@@ -4,7 +4,6 @@
from flask import Flask, Response, send_from_directory, request
app = Flask(__name__)
-app.debug = True
cpl = Completer()
@@ -32,6 +31,9 @@ def complete():
return Response(json.dumps(completions),
mimetype='application/json')
+@app.route('/debug')
+def debug():
+ return str(app.debug)
+
if __name__ == '__main__':
- port = int(os.environ.get('PORT', 5000))
- app.run(host='0.0.0.0', port=port)
+ app.run(debug=True)
View
3 completer.py
@@ -91,12 +91,15 @@ def __init__(self):
'stranger': StrangerCompleter(),
}
self.stranger_completer = self.completers['stranger']
+ self.default_completer = self.completers['stranger']
def complete(self, sources, context):
completions = []
for source in sources:
if source in self.completers:
completions += self.completers[source].complete(context)
+ if len(completions) == 0:
+ completions += self.default_completer.complete(context)
self.stranger_completer.update(context)
random.shuffle(completions)
return completions
View
3 requirements.txt
@@ -5,6 +5,9 @@ Werkzeug==0.8.3
certifi==0.0.8
chardet==1.0.1
distribute==0.6.24
+gevent==0.13.6
+greenlet==0.3.4
+gunicorn==0.14.2
nltk==2.0.1rc4
requests==0.10.8
wsgiref==0.1.2
View
8 static/css/style.css
@@ -40,10 +40,18 @@ body {
#sources {
cursor: pointer;
}
+#sources li .plus {
+ color: transparent;
+}
#sources li.selected {
font-weight: bold;
color: #ccc;
+ text-shadow: 0 0 3px rgba(200,200,200,0.5);
+}
+
+#sources li.selected .plus {
+ color: #ccc;
}
input[type=checkbox] {
View
6 static/index.html
@@ -15,9 +15,9 @@
</head>
<body>
<ul id='sources'>
- <li id='google'>Google
- <li id='austen'>Austen
- <li id='stranger'>Strangers
+ <li id='google'><span class='plus'>+</span> Google
+ <li id='austen'><span class='plus'>+</span> Austen
+ <li id='stranger'><span class='plus'>+</span> Strangers
</ul>
<div id='spinner'></div>
<div id='text' contenteditable='true'></div>
View
38 static/js/autocomplete.js
@@ -1,6 +1,7 @@
/* globals */
var selected_sources = []
var currentReq;
+var currentTimeout;
var completions;
var completionIndex;
@@ -67,29 +68,36 @@ function setupEvents() {
currentReq.abort();
currentReq = null;
completions = null;
+ $('#spinner').hide();
+ }
+ if (currentTimeout) {
+ clearTimeout(currentTimeout);
+ currentTimeout = null;
}
if (evt.which === 32) {
if (evt.ctrlKey && completions) {
showNextCompletion();
return;
}
- var ct = getCurrentTrigram();
- if (ct === '') {
- return;
- }
- $('#spinner').show()
- currentReq = $.get('/complete',
- {'sources': getSourcesList(), 'context': ct},
- function(data) {
- currentReq = null;
- $('#spinner').hide()
- if (data.length === 0) {
+ setTimeout(function() {
+ var ct = getCurrentTrigram();
+ if (ct === '') {
return;
}
- completions = data;
- completionIndex = 0;
- showNextCompletion();
- });
+ $('#spinner').show()
+ currentReq = $.get('/complete',
+ {'sources': getSourcesList(), 'context': ct},
+ function(data) {
+ currentReq = null;
+ $('#spinner').hide()
+ if (data.length === 0) {
+ return;
+ }
+ completions = data;
+ completionIndex = 0;
+ showNextCompletion();
+ });
+ }, 500);
}
});
$('#sources li').each(function() {

0 comments on commit ef8facb

Please sign in to comment.
Something went wrong with that request. Please try again.