Skip to content

Commit

Permalink
Merge pull request NYUCCL#231 from deargle/ctrl-c-kill-server
Browse files Browse the repository at this point in the history
notify user when ctrl-c kills experiment server
  • Loading branch information
gureckis committed May 10, 2016
2 parents 796c587 + 69a711d commit 693e40b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion psiturk/experiment_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ def load_user_config(self):

self.loglevels = ["debug", "info", "warning", "error", "critical"]

def on_exit(server):
'''
this is hooked so that it can be called when
the server is shut down via CTRL+C. Otherwise
there is no notification to the user that the server
has shut down until they hit `enter` and see that
the cmdloop prompt suddenly says "server off"
'''
print 'Caught ^C, experiment server has shut down.'
print 'Press `enter` to continue.'

self.user_options = {
'bind': config.get("Server Parameters", "host") + ":" + config.get("Server Parameters", "port"),
'workers': workers,
Expand All @@ -61,7 +72,8 @@ def load_user_config(self):
# 'accesslog': config.get("Server Parameters", "logfile"),
'errorlog': config.get("Server Parameters", "logfile"),
'proc_name': 'psiturk_experiment_server',
'limit_request_line': '0'
'limit_request_line': '0',
'on_exit': on_exit
}

def launch():
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
argparse==1.2.1
Flask==0.10.1
SQLAlchemy==0.8.3
gunicorn==18.0
gunicorn==19.4.5
boto==2.15.0
cmd2==0.6.7
docopt==0.6.2
Expand All @@ -14,4 +14,4 @@ fuzzywuzzy==0.2
setproctitle==1.1.8
psutil==1.2.1
Werkzeug==0.10.4
ua-parser==0.3.6
ua-parser==0.3.6

0 comments on commit 693e40b

Please sign in to comment.